# ECON 331 97/1
# ASSIGNMENT #8
# 
> restart;
# 
# a)
# Skip's utility function:
> U:=x*(y+1):
# The Lagrangian:
> L:=U+lambda*(B-Px*x-Py*y);

              L := x (y + 1) + lambda (B - Px x - Py y)

# Demand functions:
> sols:=solve({diff(L,x),diff(L,y),diff(L,lambda)},{x,y,lambda});

                     -Py + B               B + Py          B + Py
    sols := {y = 1/2 -------, lambda = 1/2 ------, x = 1/2 ------}
                       Py                  Px Py             Px

> assign(sols);
> with(plots):
> B:=10:
> Py:=1:
> plot(x,Px=0..10,labels=[`Px`,`x*`],title=`x* = x (B=10, Px, Py=1)`);
# 

> unassign('Py'):
> Px:=1:
> plot(y,Py=0..10,labels=[`Py`,`y*`],title=`y* = y (B=10, Px=1, Py)`);

# Check the nature of good Y:
> unassign('B'):
> Diff(y,B)=diff(y,B);

                     d  /    -Py + B\        1
                     -- |1/2 -------| = 1/2 ----
                     dB \      Py   /        Py

# Skip's indifference curves:
> unassign('x','y','Px','lambda'):
> implicitplot({U=10,U=20,U=30},x=0..20,y=0..20,title=`Skip's
> Indifference Map`);

# b)
# Second-order conditions:
> with(linalg):
> H:=hessian(L,[lambda,x,y]);
Warning, new definition for norm
Warning, new definition for trace

                            [ 0     -Px    -Py]
                            [                 ]
                       H := [-Px     0      1 ]
                            [                 ]
                            [-Py     1      0 ]

> det(H);

                               2 Px Py

# Since the determinant of the bordered Hessian is positive, the
# second-order sufficient condtion for a constrained maximum is
# satisfied.
# c)
# The indirect utility function:
> assign(sols);
> 'U'=simplify(U);

                                          2
                                  (B + Py)
                          U = 1/4 ---------
                                    Px Py

# d)
# The expenditure function:
> readlib(isolate):
> simplify(isolate(Uo=U,B));
# 

                                       1/2
                       B = 2 (Uo Px Py)    - Py

> B:=rhs(");

                                       1/2
                      B := 2 (Uo Px Py)    - Py

# The expenditure function reveals the minimum expenditure/income
# required to attain a specific level of utility, Uo, at given prices,
# Px and Py.  
# The partial derivatives of the expenditure function with respect to
# the prices:
> dB_dPx:=diff(B,Px);

                                     Uo Py
                       dB_dPx := -------------
                                           1/2
                                 (Uo Px Py)

> dB_dPy:=diff(B,Py);

                                   Uo Px
                     dB_dPy := ------------- - 1
                                         1/2
                               (Uo Px Py)

# e)
# Skip's expenditure minimization problem:
> unassign('x','y'):
> Z:=Px*x+Py*y+mu*(Uo-x*(y+1));

                Z := Px x + Py y + mu (Uo - x (y + 1))

# f)
# Solutions to the expenditure minimization problem:
> sols2:=simplify(solve({diff(Z,x),diff(Z,y),diff(Z,mu)},{x,y,mu}));

                                      -Px + %1       Py
             sols2 := {mu = %1, y = - --------, x = ----}
                                         %1          %1

                                       2
                     %1 := RootOf(Uo _Z  - Px Py)

> assign(sols2):
# Use the following commands to simplify 'sols2':
> x:=radsimp(convert(x,radical));

                                  1/2   1/2
                                Py    Uo
                           x := -----------
                                     1/2
                                   Px

> y:=expand(radsimp(convert(y,radical)));

                                1/2   1/2
                              Px    Uo
                         y := ----------- - 1
                                   1/2
                                 Py

# The solutions to the expenditure minimization problem are the
# 'compensated' (utility held constant) demand functions.
# Verify that the compensated demand functions are equal to the partial
# derivatives of the expenditure fuction with respect to the respective
# prices. (Hint: substitute the indirect utility function for Uo):
> subs(Uo=U,dB_dPx);

                                Uo Py
                            -------------
                                      1/2
                            (Uo Px Py)

> subs(Uo=U,dB_dPy);

                              Uo Px
                          ------------- - 1
                                    1/2
                          (Uo Px Py)

