# MAPLE ASSIGNMENT 5
# ELASTICITY
# The following commands define an inverse demand curve, compute its'
# elasticity and allow you to determine whrer the demand curve is
# elastic. 
> p:=10-y+15*exp(-0.1*y);
> plot(p,y=0..10);
> EL:=(p/y)/diff(p,y);
> plot(EL,y=0.5..10);
> fsolve(EL=-1,y);
# Now show that the demand curve is SMD and strictly convex. Then change
# p to EL and do these commands again. You should see that EL is SMI and
# strictly concave (see the plot).
> diff(p,y);
> simplify(%);
> diff(p,y$2);
> simplify(%);
# PROFIT MAXIMIZATION BY  A MONOPOLIST
# This example has a nonlinesr demand curve and a cubic strictly convex
# cost function with fixed costs =1. The first set of commands plots AR,
# MR and then the monopolist's profit function.
> AR:=10-x+15*exp(-0.1*x);
> solve(AR=0,x);
> plot(AR,x=0..14);
> TR:=x*AR;
> subs(x=5,TR);
> evalf(%);
> plot(TR,x=0..14);
> MR:=diff(TR,x);
> subs(x=5,MR);
> evalf(%);
> plot([MR,AR],x=0..14);
> fsolve(MR=0,x);
> TC:=x^3+x^2+x+1;
> plot(TC,x=0..4);
> PR:=TR-TC;
> subs(x=5,PR);
> evalf(%);
> plot(PR,x=0..4);
# Click the last plot. Then click on the profit maximizing point to
# see approximately what the solution to the profit maximization problem
# is. Now plot TR, TC & PR in the same graph. Which curve is which? If
# you would like to add a title to your plot, put labels (names) on the
# axes or on the curves, ask your TA and s/he will show you how.
> plot([TR,TC,PR],x=0..4);
> MC:=diff(TC,x);
> AC:=TC/x;
> subs(x=5,AC);
> plot([MC,AC],x=0..4,y=0..100);
> plot([MR,AR,MC,AC],x=0..6,y=0..100); 
# Which curve is which in your last plot? Use the pointer to get an
# approximation to the optimal output choice and the price that the
# monopolist will charge for this output. Compare the values that you
# get to the actual values computed below.
> optx:=fsolve(MR=MC,x,0..6);
> optp:=subs(x=optx,AR);
> evalf(%);
> PRmax:=subs(x=optx,PR);
> evalf(%);
# Now plot profits again. The showtangent command should illustrate the
# optimal choice of x by plotting the tangent line to PR at its maximum
# point. 
> with(student):
> showtangent(PR,x=optx,x=0..4);
# For an example with a U-shaped MC curve you can use the TC curve 
# below. Execute the commands down to the end. Then go back and
# reexecute the commands from plot(MR,AR,MC,AC) on to recalculate the
# optimal choices of the monopolist.  If you then increase the 11 in TC
# to 21 and reexecute the
# MC and AC commands, you will have an example where maximum profits are
# negative but still > PR(0). If you further increase the 21 in TC to 31
# you will have an example where MR < MC for all x and the monopolist
# will shut down. 
# Maple will not solve for optx because there is no optx so replace optx
# in the showtangent
# command by some specific number..
> TC:=x^3-4*x^2+11*x+10;
> plot(TC,x=0..4);
> MC:=diff(TC,x);
> AC:=TC/x;
> plot({AC,MC},x=0..4,y=0..50);
> PR:=TR-TC;
> plot(PR,x=0..4);
> 
# SUPPLY CURVE OF PERFECT COMPETITOR
# The following is an example of cost function a firm night have. First
# click the restart (the last) button on the toolbar so that p becomes
# undefined again. Then have a look at the graph of the cost function 
# and  the graphs of MC, AC and AVC. 
> TC:=x^3-4*x^2+11*x+10;
> plot(TC,x=0..4);
> MC:=diff(TC,x);
> AC:=TC/x;
> FC:=subs(x=0,TC);
> AVC:=(TC-FC)/x;
> plot({MC,AVC,AC},x=0..4,y=0..50);
# You should be able to identify each of the curves in the above plot.
# Next determine the output which minimzes MC. Check the answer by
# clicking on this point 
# in the above plot.
> MMC:=diff(MC,x);
> xminmc:=solve(MMC=0,x);
> MCmin:=subs(x=xminmc,MC);
# Now the expression for profits can be defined. 
> PR:=p*x-TC;
# To sketch the graph of profits, a specific price must be chosen.
> AR:=15;
> TR:=AR*x;
> PRspec:=subs(p=AR,PR);
> plot([TR,TC,PRspec],x=0..5);
# You can also solve the firm's profit maximizing problem,
> xopt:=[fsolve(AR=MC,x)];
> subs(x=xopt[2],PRspec);
# You can see that profits are positive  Now change pr=AR to some lower
# value and redo the above commands. When you set it low enough, below
# minimum AC but above minimum AVC, profits will be negative but above
# -FC. If set below minimum AVC but above minimum MC, profits will be
# less than -FC and the optimal x is x=0. If set below minimum MC, there
# is no solution for xopt. 
# The next commands determine the lowest price at which the firm would
# be willing to produce a positive output. (i.e. where MC=pr=AVC). Here
# solve produces more than one solution so an extra step is needed to
# pick out the right solution. Secondly, the x which minimizes AC is
# calculated.
> x1:=[solve(AVC=MC,x)];
> xminavc:=x1[2];
> AVCmin:=subs(x=xminavc,AVC);
> subs({p=AVCmin,x=xminavc},PR);
> xminac:=fsolve(MC=AC,x);
> ACmin:=subs(x=xminac,AC);
> subs({p=ACmin,x=xminac},PR);
# The last answer should be 0 but there is a small rounding error.
# The following commands plot the inverse supply curve, the supply curve
# and show where profits become nonnegative. Parametric plots are used
# so that the vertical section can be plotted. In each plot, change the
# axes to framed
# to see this section.and the dicontinuity in the supply curve. (Ask
# your TA for an explanation of parametric plots if you don't understand
# what is happening here).
> plot([[x,MC,x=xminavc..4],[0,p,p=0..AVCmin]]);
> plot([[MC,x,x=xminavc..4],[p,0,p=0..AVCmin]]);
> plot([[x,MC,x=xminavc..4],[0,p,p=0..AVCmin],[x,AVCmin,x=0..xminavc]]);
# The firm's maximized profit function is PRmax(p)=PR(p,x(p)) where x(p)
# is the supply curve. The next command defines PRmax(p(x)) and
# the following command plots PRmax(p). Check by clicking on the plot
# that profits do not become positive until p=ACmin.
> PRmax:=subs(p=MC,PR);
> plot([[MC,PRmax,x=xminavc..4],[p,-FC,p=0..AVCmin]]);
> 
