# ECON 331  97/1
# ASSIGNMENT 5
# 
# QUESTION 1
# 
> restart;
# 'Inverse' production function:
> z:=q^3+4*q:
# Average revenue function:
> p:=10-2*q:
# Total revenue function:
> R:=p*q;

                          R := (10 - 2 q) q

# Find diff(R,z) by the chain rule and the inverse function rule:
> dR_dz:=diff(R,q)*(1/diff(z,q));

                                   -4 q + 10
                          dR_dz := ---------
                                      2
                                   3 q  + 4

# The point elasticity of total sales revenue with respect to the amount
# of labour used is:
> epsilon:=dR_dz*z/R;

                                           3
                             (-4 q + 10) (q  + 4 q)
                  epsilon := -----------------------
                                 2
                             (3 q  + 4) (10 - 2 q) q

# When q=2, the elasticity is:
> q:=2:
> 'epsilon'=epsilon;

                            epsilon = 1/6

# 
# QUESTION 2
# 
> restart;
> with(linalg):
Warning, new definition for norm
Warning, new definition for trace
# Enter the system of equations as a vector:
> A:= vector([x*y-w,y-w^3-3*z,w^3+z^3-2*w*z]):
# The Jacobian for the system is:
> J:=jacobian(A,[x,y,w]);

                          [y    x        -1    ]
                          [                    ]
                          [                2   ]
                     J := [0    1      -3 w    ]
                          [                    ]
                          [             2      ]
                          [0    0    3 w  - 2 z]

# Since z is treated as exogenous, the right hand side column vector can
# be generated as follows:
> b:=jacobian(A,[z]);

                               [    0     ]
                               [          ]
                          b := [    -3    ]
                               [          ]
                               [   2      ]
                               [3 z  - 2 w]

# Use the map command to change the signs of the elements:
> d:=map(x->-x,b);

                               [     0     ]
                               [           ]
                          d := [     3     ]
                               [           ]
                               [    2      ]
                               [-3 z  + 2 w]

# We can find expressions for the following derivatives by solving the
# system:
> matrix(3,1,[Diff(x,z),Diff(y,z),Diff(w,z)]) = multiply(inverse(J),d);

                     [               2           2       ]
                     [         (3 x w  - 1) (-3 z  + 2 w)]
                     [-3 x/y - --------------------------]
            [d   ]   [                     2             ]
            [-- x]   [               y (3 w  - 2 z)      ]
            [dz  ]   [                                   ]
            [    ]   [             2      2              ]
            [d   ]   [            w  (-3 z  + 2 w)       ]
            [-- y] = [      3 + 3 ----------------       ]
            [dz  ]   [                  2                ]
            [    ]   [               3 w  - 2 z          ]
            [d   ]   [                                   ]
            [-- w]   [                2                  ]
            [dz  ]   [            -3 z  + 2 w            ]
                     [            -----------            ]
                     [               2                   ]
                     [            3 w  - 2 z             ]

# Assign values to:
> w:=1:
> z:=1:
# Solve for (x,y) :
> sols:=solve({x*y-w,y-w^3-3*z},{x,y});

                       sols := {y = 4, x = 1/4}

# Assign these values to x,y:
> x:=1/4:
> y:=4:
# Now the vector of derivatives is:
> multiply(inverse(J),d);
# So, diff(x,z)=-1/4 .

                                [-1/4]
                                [    ]
                                [ 0  ]
                                [    ]
                                [ -1 ]

# 
# QUESTION 3
# 
> restart;
# Equation:
> F:=x^2+y^2+z^2+x*y+x*z+y*z+x+y+z-1;

               2    2    2
         F := x  + y  + z  + x y + x z + y z + x + y + z - 1

# Partial derivatives:
> dz_dx:=implicitdiff(F,z,x):
> Diff(z,x) = dz_dx;

                       d        y + 2 x + 1 + z
                       -- z = - ---------------
                       dx       2 z + x + y + 1

> dz_dy:=implicitdiff(F,z,y):
> Diff(z,y) = dz_dy;

                       d        2 y + x + z + 1
                       -- z = - ---------------
                       dy       2 z + x + y + 1

# At (x,y,z)=(1,-1,-1) the function F has continuous partials. We can
# check to see if  diff(F,z) is nonzero:
> dF_dz:=diff(F,z);

                       dF_dz := 2 z + x + y + 1

> x:=1:
> y:=-1:
> z:=-1:
> is(dF_dz=0);

                                false

# So the implicit function z=f(x,y) exists, and the partial derivatives
# are:
> dz_dx;

                                  1

> dz_dy;

                                  -1

