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

### Price Elasticity and Marginal Expenditures

This section begins with the demand curve that has been used 
above. This demand curve exhibits constant elasticity. That is,
the price elasticity of demand is the same at all points on the demand 
curve. The next cell replicates the specifications from the previous
section. We use this constant-elasticity demand curve for now.

[DQ(p,a,E):=a*p^E,    DP(q,a,E):=(q/a)^(1/E)];
[SQ(p,b,c):=b+c*p,    SP(q,b,c):=(q-b)/c];

TeX: 
The demand curve appears twice in the input group below.
It is evaluated for a = 1200 and E = -2.5 at two prices, 
p = 9.9 and p = 10.1. We use the midpoint formula
Earc = ((q2 - q1}/q_{mean) / ((p2 - p1)/{p_{mean). 

[DQ(p,a,E):=a*p^E,    DP(q,a,E):=(q/a)^(1/E)];
[SQ(p,b,c):=b+c*p,    SP(q,b,c):=(q-b)/c];
[[q1, q2]: [DQ(9.9, 1200, -2.5), DQ(10.1, 1200, -2.5)],
((q2 - q1)/(0.5*(q2+q1)))/(0.2/10)];

The graph below shows three constant-elasticity demand curves with different 
price elasticities. The first is elastic ($E = -2.5$), the second is 
unit elastic ($E = -1$), and the third is inelastic ($E = - 0.25$). 
The three curves intersect when $p = 1$, with $q = a = 1200$, as noted earlier.

wxdraw2d(yrange=[0,3],xlabel="Quantity",ylabel="$ per unit",
 user_preamble="set key bottom left", key="Elastic", 
 explicit(DP(q, 1200, -2.5), q, 1, 1500 ), line_width=2,
 key="Unit Elasticity", color=blue, 
 explicit(DP(q,1200,-1),q,1,1500), color = red, line_width = 3, 
 key = "Inelastic", explicit(DP(q, 1200, -0.25), q, 1, 1500 ))$

### Elasticity, Price, and Expenditures

When the demand curve is price elastic, price and total 
spending are inversely related; when the demand curve is 
price inelastic, price and total spending change in the 
same direction; and when the demand curve's elasticity 
is -1.0, total spending is the same at each price.
The cell below shows that MR = p + (dp/dq)*q, which is 
equivalent to MR = p*(1 + 1/Ep) -- or p*(1 + Ep)/Ep -- 
which generates the relationshp stated in the previous sentence.

[depends(p, q),  TR : p*q,  MR : diff(TR, q)];

The next cell shows the expressions for the total revenue and 
the marginal revenue for a constant-elasticity demand curve.

[TR(q, a, E) :=q*(q/a)^(1/E),  MR: diff(TR(q, a, E),q), 
subst(p,(q/a)^(1/E), factor(MR))];

The next figure shows an elastic demand curve and the 
associated marginal revenue curve (MR > 0), and an inelastic
demand curve and the associated marginal revenue curve (MR< 0).
If a unitary-elastic (E = -1) were added, the marginal revenue
would be zero.

MR(q,a,E):=''(DP(q,a,E)*(1+1/E));  
wxdraw2d(yrange=[-2,5], xaxis=true, yrange=[-5,15],
 xlabel="Quantity",ylabel="$ per unit",line_width=2,
 key="Demand, Elastic",explicit(  DP(q,1200,-2.5),q,1,1500 ),
 key="MR, Elastic Demand", color=blue,
 explicit(MR(q,1200,-2.5),q,1,1500), line_width=3,color=red,
 key="Demand, Inelastic", explicit(DP(q,1200,-0.5),q,1,1500 ),
 color =gray40,key="MR, Inelastic Demand",
 explicit(MR(q, 1200, -0.75), q, 1, 1500 )   )$

### A Linear Demand Curve

Linear demand curves have constant slopes and varying elasticities.

p : a + b*q$   TR : expand(p*q)$
MR : diff(TR, q)$ E : (p/q)/(diff(p, q))$
matrix(["price","Total Revenue","Marginal Revenue",
        "Elasticity"],  [p, TR, MR, E]);

On a linear demand curve, unitary elasticity (E = -1) occurs at
the midpoint of the line segment.

subst(q = 0.5*(-a/b),E);   /* or*/ solve(E=-1,q);

TeX: The example below illustrates these conclusions.

matrix(["pL","TRL","MRL","EL"],
[pL : 400 - 2.5*q,  TRL : expand(pL*q),
MRL : diff(TRL, q),EL : -0.4*(pL/q)]);

TeX: We graph the demand curve and the marginal 
revenue curves in one panel and the elasticity function
separately. Elasticity is a pure, unit-free
number, so it can be used to compare price
elasticities across products.
The graphs confirm that the elasticity equals -1 at 
the midpoint on the demand curve (where $q = 80$).
Also, at that point $MRL = 0$.
\index{commands!gr2d}

D_MR:
 gr2d( xlabel = "Quantity", ylabel = "$ per unit",
 xaxis=true,line_width=2,key="Demand",explicit(pL,q,0,160),
 color=blue, key = "MR", explicit(MRL, q, 0, 160),
 ytics = {-200, 0, 200}, xtics ={0, 80, 160},
 user_preamble="set key bottom left" )$
Elasticity:
 gr2d(user_preamble="set key bottom right",
 xlabel="Quantity",ylabel="No units",yrange=[-5,1],
 xaxis=true,ytics={["-5.0",-5],["-1.0",-1],["1.0",1]}, 
 line_width=2,explicit(-1,q,0,160),color=red, 
 key="Elasticity",explicit(EL,q,0,160),xtics={0,80,160})$
 
wxdraw(D_MR, Elasticity,dimensions=[360,360])$

### Other Elasticities

Other elasticities that play roles in economic analysis include
these: the cross-price elasticity of demand (with respect to prices 
of related goods), the income elasticity of demand, and the price 
elasticity of supply
The cell below replaces the earlier one with a function that 
exhibits constant elasticities of demand with respect to the 
good's own price, the price of a related good, and income (labeled
ED, EDR, and EDY respectively).

kill(all)$ DQ(p,a,ED,pr,EDR,y,EDY):=a*p^ED*pr^EDR*y^EDY; 
DP(q,a,ED,pr,EDR,y,EDY):=(q/(a*pr^EDR*y^EDY))^(1/ED);

Two prices of a related good and two income levels generate
four possible demand curve equations, as indicated.

[pr0,y0]:[2,1000]$  [pr1,y1]:[5,1500]$
[a0,ED0,EDR0,EDY0]:[10,-0.8,-0.2,0.4]$
[DP(q,a0,ED0,pr0,EDR0,y0, EDY0), 
 DP(q,a0,ED0,pr1,EDR0,y0,EDY0),
 DP(q,a0,ED0,pr0,EDR0,y1,EDY0),
 DP(q,a0,ED0,pr1,EDR0,y1,EDY0)];

Cross-Price Elasticity of Demand
The graph below expands slightly on the one in the text.
It contains a title that indicates the value of EDR, and 
the key shows the two prices of the related good. All three
changes involve the concat( ) and string( ) commands.

string(EDR0);

wxdraw2d(title = 
 concat("Cross-price elasticity = ", string(EDR0)),
 yrange=[0,500],xlabel="Quantity",ylabel="$ per unit", 
 key = concat("Demand, pr =",pr0), line_width=2,
 explicit(DP(q,a0,ED0,pr0,EDR0,y0,EDY0),q,.1,5),
 color=blue, key=concat("Demand, pr =",string(pr1)),
 explicit(DP(q,a0,ED0,pr1,EDR0,y0,EDY0),q,.1,5))$

Suppose that EDR = +0.2, rather than -0.2. Then, of
course, the demand curve's shift is to the right when
pr increases. This good and the related good are
substitutes for each other.

wxdraw2d(title = 
 concat("Cross-price elasticity = ", string(EDR0)),
 yrange=[0,500],xlabel="Quantity",ylabel="$ per unit", 
 key = concat("Demand, pr =",pr0), line_width=2,
 explicit(DP(q,a0,ED0,pr0,0.2,y0,EDY0),q,.1,5),
 color=blue, key=concat("Demand, pr =",string(pr1)),
 explicit(DP(q,a0,ED0,pr1,0.2,y0,EDY0),q,.1,5))$

Income Elasticity of Demand
Most goods are normal goods, for which income elasticities are
positive. Normal goods fall into two categories, those for which
EDY > 1 and those for which EDY < 1 (and, trivially, those for 
which EDY = 1). This distinction is important in that it determines
the effect of an income change on the share of income spent on the
good, other things equal.
The cell below shows that the increased income causes increased
demand for this good.

[DQ(p,a0,ED0,pr0,EDR0,y0,EDY0),
 DQ(p,a0,ED0,pr0,EDR0,y1,EDY0)];

The cell below confirms that the midpoint formula, applied to the 
discrete shift in the demand curve, yields approximately the value 
of EDY, 0.4.
Confirm that the formula for the arc elasticity is consistent with
the one applied earlier to the effect of a price change.

pctChD: 2*(DQ(p,a0,ED0,pr0,EDR0,y1,EDY0)- DQ(p,a0,ED0,pr0,EDR0,y0,EDY0))/
(DQ(p,a0,ED0,pr0,EDR0,y0,EDY0) + DQ(p,a0,ED0,pr0,EDR0,y1,EDY0));
pctChy: 2*(y1-y0)/(y1+y0);
[pctChD/pctChy, EDY0];

Because 0< EDY0 < 1, increased income causes the quantity demanded
to increase, given the price, but the share of income spent on the
good to decrease. 

EXP0:3*(DP(3,a0,ED0,pr0,EDR0,y0,EDY0))$  
EXP1:3*(DP(3,a0,ED0,pr0,EDR0,y1,EDY0))$ 
matrix(["Income","Spending","Share"],
        [y0,EXP0,EXP0/y0],[y1,EXP1,EXP1/y1]);

Supply Elasticity
The concept of the price elasticity of supply differs little from that of 
its counterpart for demand. 

transpose(matrix(
 ["General Supply Curve", "General Inverse Supply Curve",
 "Specific Supply Curve", "Quantity Supplied"],
[SQ(p,b,ES):= b*p^ES,  SP(q,b,ES):=(q/b)^(1/ES), 
 SQ(p, 40, 0.5),       SQ(1.5, 40, 0.5)]));

TeX: The graph below shows three supply curves. The curve 
exhibiting unitary elasticity is a ray through the origin. 

wxdraw2d(user_preamble="set key top left", xlabel=
"Quantity",yrange=[0,2],ylabel="$ per unit",key=
"Unitary Elasticity",
line_width=2,
explicit(SP(q,40,1),q,0,75),
 key="Inelastic",color=blue,explicit(SP(q,40,.5),
  q,0,75),key="Elastic",color=red, 
 explicit(SP(q, 40, 1.5), q, 0, 75) )$

When a supply curve is linear, its p-axis intercept 
determines whether it is elastic, inelastic, or exhibits
unitary elasticity. If q = a + b*p, then the p-axis intercept
is -a/b. We assume that b > 0, so a > 0 implies a negative
p-interept, which corresponds to an inelastic demand.

matrix(
["Linear Supply Equation", "Elasticity","Elasticity Limit"],
[q:a + b*p, b*p/q,  limit(b*p/q,p,inf)]);