load(draw)$ fpprintprec:5$ ratprint:false,
set_draw_defaults(  fill_color=gray40,color=gray10, 
draw_realpart=false,font_size=10)$
kill(all)$

# Chapter 2. Simple Economic Models

This chapter illustrates two models using Maxima, the simple
production possibilities model and the market model based on
demand and supply. 

## Production Possibilities

Perhaps the most abstract model of an economy is
the production possibilities curve(PPC), which reduces the 
economy to two goods and places only quite general conditions 
on the functional relationship between the two goods.

### An Illustrative Example

We impose a specific functional form on the PPC, 
y = a + b*x^2.5, where a >0 and b < 0. = 0. 

Before graphing the function, we use find_root( ) to 
ensure that all points are in the first quadrant. We 
add some material to that in the text. We use solve( )
as well as find_root, which is moved to a later cell.
The asssume( ) command avoids a query regarding the sign
of a*b.

assume(a>0,b<0)$  f(x,a,b):=a+b*x^2.5;    
solnx: solve(f(x,a,b),x);

Only the fifth solution is real, so we can define 
xmax = (-a/b)^2/5). After we determine the numerical
approximation, given a pair of parameter values, we
evaluate the variable xmax.

xmax : rhs(solnx[5]);

Given the parameter values below, x1max is approximately
75.786.

[a1,b1]:[500,-0.01];  
x1max : find_root(f(x, a1, b1), 0, 1000);

To our specified print precision evaluating xmax with
these parameter yields the same result. 
Execute the command below once more, without float( ).

float(subst([a=a1,b=b1],xmax));

The wxdraw2d( ) command below plots a single
explicit function, the production possibilities curve. The 
x and y ranges are set at 1.1 times the maximum value of
x (x1max from above) and of y, which equals a1. Inside the
explicit( ) command, x ranges from 0 to x1max. 

wxdraw2d( xlabel="Good x", ylabel="Good y",
 yrange = [0, 1.1*a1], xrange = [0, 1.1*x1max], 
 line_width=2,explicit(f(x,a1,b1),x,0,x1max))$

### Opportunity Costs

The second implication of the graph is the existence of 
trade-offs. 

The cell below expands the one in the text slightly, by
creating tables with labels. It also adds the values of the
two changes in y due to 3.7893 unit changes in y at two
different points on the PPC.

[x1, x2, dx] : [x1max/5, x1max/2, x1max/20]$
matrix(["First initial x", "Second initial x", "Change in x"],[x1,x2,dx]);
[y1, y1d] : [f(x1, a1, b1), f(x1 + dx, a1, b1)]$
[y2, y2d] : [f(x2, a1, b1), f(x2 + dx, a1, b1)]$
matrix(["Initial y", "Post-change y","Change in y"],
[y1,y1d,y1d-y1],[y2,y2d,y2d-y2]);

The next graph adds these four points to the PPC.
Except for changing the color and the type of point
representation, this is the same as in the text.

wxdraw2d(xlabel="Good x",ylabel="Good y",
 yrange=[0,1.1*a1],xrange=[0,1.1*x1max],line_width=2, 
 explicit(f(x,a1,b1),x,0,x1max),point_size=2,
 color=blue, point_type=filled_circle,
 points([x1,x1+dx,x2,x2+dx],[y1,y1d,y2,y2d]) )$

The cell below calculates the opportunity cost of x 
over the ranges considered above.

oc1 : -(y1d - y1)/(dx)$   oc2 : -(y2d - y2)/(dx)$
matrix(["Opportunity cost, 1st range",
"Opportunity cost, 2nd range"],[oc1, oc2]);

The graph below shows opportunity cost as a continuous 
function of x. The opportunity cost at any point on the 
PPC is the negative of the PPC's slope at that point. 

/* Observe the use of ''( ) to instruct Maxima to
   evaluate the function. */
g(x, a1, b1) := -''(diff(f(x, a1, b1), x));
wxdraw2d(ylabel = "Good y per unit of Good x",
 title = "Opportunity Costs: Function and Points", 
 xlabel = "Good x",explicit(g(x, a1,b1),x,0,x2+2*dx),
 color=blue, point_size=2,points([(x1+dx/2),
 (x2+dx/2)],[oc1,oc2]))$

### Shifting PPC

A change in either the resource availability  or technology
shifts the PPC.

[a2,b2]:[500,-0.0075]$ x2max:find_root(f(x,a2,b2),0,1000)$
[x1max,x2max]; ymax:max(a1,a2)$  xmax:max(x1max,x2max)$
wxdraw2d(title="PPC shift: lower b value",xlabel="Good x",
ylabel = "Good y", yrange=[0,1.1*ymax],xrange=
 [0,1.1*xmax],key="Initial PPC", line_width=2, explicit(
 f(x,a1,b1),x,0,xmax),color=gray,key="New PPC",
 explicit(f(x,a2,b2),x,0,xmax))$

We can animate the graph above by replacing b2 with 
new_b in the second explicit( ) command. As always, the
first two entries in with_slider_draw( ) must be the name
of the parameter to be shifted and a rule for making a
list of values.

with_slider_draw(new_b,makelist(b1*(1+.2*(i-4)),i,2,6),
xlabel="Good x",
ylabel = "Good y", yrange=[0,1.1*ymax],xrange=
 [0,1.1*xmax],key="Initial PPC", line_width=2, explicit(
 f(x,a1,b1),x,0,xmax),color=blue,key=concat("New PPC, b = ",
string(new_b)),
 explicit(f(x,a2,new_b),x,0,1.5*xmax))$

load(draw)$ fpprintprec:5$ ratprint:false,
set_draw_defaults(  fill_color=gray40,color=gray10, 
draw_realpart=false,font_size=10)$
kill(all)$