# ECON 331  97/1
# ASSIGNMENT #6
# 
# QUESTION 1
# 
> restart;
# 
# Function, f(z):
# 
> f:=z->z^4-6*z^3+12*z^2-10*z+37;

                          4      3       2
               f := z -> z  - 6 z  + 12 z  - 10 z + 37

# 
# Second-order derivative function, f''(z)''(z):
# 
> f2:=diff(f(z),z$2);

                                 2
                       f2 := 12 z  - 36 z + 24

# 
# Evaluate the second-order derivative at z=1:
# 
> subs(z=1,f2);

                                  0

# 
# Since f''(1)''(1) = 0, the stationary point is not a unique extremum. 
# In fact, since f'''(1) <0, the stationary point is a point of
# inflection:
# 
> f3:=diff(f(z),z$3);

                           f3 := 24 z - 36

> subs(z=1,f3);

                                 -12

# 
# QUESTION 2
# 
> restart;
# 
# Average revenue:
# 
> AR:=-y^3+12*y^2-30*y+1000;

                           3       2
                   AR := -y  + 12 y  - 30 y + 1000

# 
# Average Cost:
# 
> AC:=2*y+1000-100/y;

                                           100
                        AC := 2 y + 1000 - ---
                                            y

# 
# The profit function, pi(y):
# 
> pi:=expand(AR*y-AC*y);

                           4       3       2
                   pi := -y  + 12 y  - 32 y  + 100

# 
# The first-order condition for a maximum is satisfied at the following
# values for y:
# 
> sols:=solve({diff(pi,y)},{y});

                                      1/2                    1/2
    sols := {y = 0}, {y = 9/2 + 1/2 17   }, {y = 9/2 - 1/2 17   }

# 
# The second-order derivative function, pi''(y):
# 
> soc:=expand(diff(pi,y$2));

                                  2
                      soc := -12 y  + 72 y - 64

# 
# Substitute the solutions to the first-order condition into the
# second-order derivative function to check the second-order condition
# for a unique maximum, pi''(y) < 0.  Evaluate the profit function for
# those solutions which satisfy the second-order condition:
# 
> subs(sols[1],soc);

                                 -64

> subs(sols[1],pi);

                                 100

> evalf(subs(sols[2],soc));

                             -108.2159013

> evalf(subs(sols[2],pi));

                              258.639194

> evalf(subs(sols[3],soc));

                              40.2159013

# Solution (3) violates the second-order condition.  Solution (2)
# generates the global maximum for pi(y).  The profit maximising output
# (in floatinf point format) is:
# 
> evalf(sols[2]);

                          {y = 6.561552813}

# 
# A plot of the function, pi(y):
# 
> plot(pi, y=-1.5..8.5);

