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

# Demand Theory: Constraints 
               and Optimization

This chapter introduces the budget constraint and 
combines the budget constraint with the preferences developed in the 
preceding chapter to provide a model of rational consumer
choice. 

## Budgets and Budget Constraints

## Indifference Curves and Choice

### Optimization: Choosing the Best 
  Combination

The preceding workbook shows that the CES function generates 
an income consumption curve that is a ray through the origin.
Functions like this one are homothetic. This section continues
by examining functions that are not homothretic.

### Nonhomothetic Functions

The function below is an example of a nonhomothetic function. 
The mrs is unrelated to y and is a function of x, so it cannot be 
the same for all values of y/x.

The next section illustrates a special case of a nonhomothetic
utility function, one that results in one of the goods being inferior
(other things equal, the quantity selected is inversely related to 
income).

[px0,py0,m0]:[50,12,1200]$  
v(x,y):=x+log(y)$  solve(x+log(y)=v0,y)$  
icv(x,v0):=''(rhs(%[1]))$  
mrsv(x,v0):=''(diff(icv(x,v0),x))$
matrix(["Utility","Indifference Curve","mrs"],
   [v(x,y),  icv(x,v0), mrsv(x,v0)]);

The income consumption curve for this function is a
horizontal line, the height of which is px/py. 

soln:solve(mrsv(x, v)=-px/py, x)$
icc(px, py):=''(icv(rhs(soln[1]), v));

[v01,v02,v03] : [4,5,6]$       
[xv1,xv2,xv3] : 
 [find_root(diff(icv(x,v01),x) =-px0/py0,x,0,50),
 find_root(diff(icv(x,v02),x) =-px0/py0,x,0,50),
 find_root(diff(icv(x,v03),x) =-px0/py0,x,0,50)]$
[yv1,yv2,yv3]:float([icv(xv1,v01), icv(xv2,v02),
  icv(xv3,v03)])$                
[mv1,mv2,mv3]:[px0*xv1+py0*yv1,px0*xv2+py0*yv2,
  px0*xv3+py0*yv3]$        
matrix(["x","y","m"], [xv1,yv1,mv1],[xv2,yv2,mv2],
  [xv3,yv3,mv3]  );

The graph below illustrates the implication of this 
function's nonhomotheticity. Over the income range
considered, any income change translates into 
a change in spending on x; the amount of y consumed
remains constant.

wxdraw2d( xlabel = "Good x", ylabel = "Good y", 
 yrange = [0, mv3/py0], 
 line_width = 2, key = "v0 = v01", 
 explicit(icv(x, v01), x, 0, mv3/px0),    key = "", 
 explicit(mv1/py0 - (px0/py0)*x, x, 0, mv1/px0),
 color = red,key = "v0 = v02", 
explicit(icv(x, v02), x, 0, mv3/px0), key = "",
explicit(mv2/py0 - (px0/py0)*x, x, 0, mv2/px0),
color = black, key = "v0 = v03", 
explicit(icv(x, v03), x, 0, 1.1*mv3/px0),  key = "", 
explicit(mv3/py0 - (px0/py0)*x, x, 0, mv3/px0),
key="ICC",line_width=1, line_type=dots,
explicit(icc(px0, py0), x, 0, mv3/px0)    )$

The income elasticity of x over this range exceeds
1.0 (it must, given that all additional income is 
spent on x), and it becomes smaller as income increases.

That EI = m/(px*x) for all positive values of x implies
both of these results and a bit more: EI must decrease
as m increases and its limit is 1.

EI:[mv1/(px0*xv1),mv2/(px0*xv2), mv3/(px0*xv3)]$
matrix(["Income","Income Elasticity"], [mv1,EI[1]],
    [mv2, EI[2]], [mv3, EI[3]]);

For m/py < 4.1667, the consumer cannot consume
any combination of x and y on the ICC depicted above. 
For lower income levels, this consumer 
buys only y, and the equality of the mrs and px/py
no longer holds.

For these lower income levels, the utility function is 
v(0,y) = log(y). The cellbelow shows three utility levels, 
the relative price levels, the mrs values, y values, 
and the requisite m values. For all, mrs <= px/py.

[v04,v05,v06] :  float(
 [log(px0/py0), 0.8*log(px0/py0), 0.4*log(px0/py0)])$
p: float(px0/py0)$         [mrs4, mrs5, mrs6]:float(
[-mrsv(0, v04), -mrsv(0, v05), -mrsv(0, v06)])$
[y4, y5, y6] : float([exp(v04), exp(v05), exp(v06)])$
[mv4, mv5, mv6]:[py0*y4,py0*y5,py0*y6]$  
matrix(
  ["Income","y","Utility","mrs","px/py"],[mv4,y4,v04,
    mrs4,p],[mv5,y5,v05,mrs5,p],[mv6,y6,v06,mrs6,p]);

TeX: The graph below complements the preceding graph, 
which shows the horizontal segment of the income-consumption curve. 

The graph below differs from that in the text in that the
vertical axis is extended slightly and part of the horizontal 
section of the ICC is included.

wxdraw2d(xlabel="Good x", ylabel="Good y",yrange=[0,4.5],
 xrange=[0,1], dimensions=[640,480],
 line_width=2, key="v0 = v04", 
 explicit(icv(x,v04),x,0, mv4/px0),key="mv = mv4", 
 explicit(mv4/py0 - (px0/py0)*x, x, 0, mv4/px0),
 color=red,key="v0 = v05", 
 explicit(icv(x,v05),x,0,mv4/px0), key="mv=mv5",
 explicit(mv5/py0-(px0/py0)*x,x,0,mv5/px0),  
 color=black,key="v0 = v06", 
 explicit(icv(x, v06),x,0, mv4/px0),key="mv=mv6", 
 explicit(mv6/py0-(px0/py0)*x,x,0,mv6/px0),
 line_width=1, key="ICC section", 
 explicit(icc(px0, py0), x, 0, 0.7)      )$

### An Inferior Good

In the CES illustration, both x and y are normal goods. In the second
case, y is a normal good for low income levels while x's income 
elasticity is zero. For higher incomes, the roles reverse: x's income
elasticity is positive and y's is zero. So we have seen cases of positive
and zero income elasticities of demand.

A third possibility is that income elasticities
of demand for one or more goods are negative. One utility
function that can exhibit a negative income elasticity for one
of the two goods appears below.

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

kill(all)$  
u(x,y,a,b,c):=a*log(x)+b*log(y)+c*x*y;

We begin by creating a functional expression for the mrs that
is derived from the function above.

mrs(x, y,a,b,c) := 
''(ratsimp(diff(u(x,y,a,b,c),x)/diff(u(x,y,a,b,c),y)));

To convert this to an expression in terms of x and the parameters,
substitute the value of y that the budget line implies into the
function above. The result is below. (A comment is used to indicate
where the expression for y is entered.)

mrs_aug(a,b,c,m,x,p):=''(mrs(x, /*y = */ m-p*x    ,a,b,c));

The next cell specifies a set of parameter values and begins
an analysis of this function.

The solve command cannot be used to determine the points at 
which the mrs_aug( ) function equals a given price ratio, so
find_root( ) is used. First, we examine the behavior of 
mrs(a0,b0,c0,m)-p0 for two values of m.

The cell below shows that each of the two expressions has a 
root between x=20 and x=30. For larger values, no roots exist,
and for some larger values the expression is not defined.

[p0, m0, m1]:[0.2,22.5,20]$ [a0,b0,c0]:[40,50,-0.1]$
wxdraw2d( yrange=[-2*p0, 2*p0],xaxis=true,xlabel="x",
 title="Marginal Rates of Substitution",ylabel=
"y per unit of x", key=concat("mrs-p0,m =",string(m0)),
 explicit(mrs_aug(a0,b0,c0,m0,x,p0)-p0,x,0.1,200),
 line_width=2,key=concat("mrs - p0,m =",string(m1)),
 explicit(mrs_aug(a0,b0,c0,m1,x,p0)-p0,x,0.1,200))$

Based on the graph, we apply find_root twice. In each case
the search range is from 1 to 30. The values of x are 
determined, along with the implied values of y and u.

x0: find_root(mrs_aug(a0,b0,c0,m0,x,p0)-p0,x,1,30)$
    y0: m0-p0*x0$     u0:u(x0,y0,a0,b0,c0)$
x1: find_root(mrs_aug(a0,b0,c0,m1,x,p0)-p0,x,1,30)$    
    y1: m1-p0*x1$     u1 : u(x1,y1,a0,b0,c0)$
matrix(["m", "x", "y", "u"], [p0*x0+y0, x0, y0, u0],  
      [y1+p0*x1, x1, y1, u1]);

When m decreases from 22.5 to 20.0, the utility-maximzing
quantity of x increases from 20.145 to 23.225. The graph 
below shows the indifference curves and budget lines that 
correspond to this result.

wxdraw2d(user_preamble="set key bottom",xlabel="x",
 ylabel="y", line_width=2,dimensions=[640,480],
 point_type=asterisk,
 key = "Income consumption curve segment",
 points_joined=true,points([[x0,y0],[x1,y1]]), 
 key="u = u0",line_width=1, 
 implicit(u(x,y,a0,b0,c0)-u0,x,0.1,25,y,0.1,30),
 key="m0 - p0*x",explicit(m0-p0*x,x,0,50),color=red, 
 line_width=2,key="u = u1",implicit(u(x,y,a0,b0,c0)-u1,
  x,0.1,50, y, 0.1, 30),key="m1 - p0*x, m1 < m0", 
 color=black,explicit(m1-p0*x,x,0,50))$

The bold line segment connecting the two points approximates a 
segment of the income consumption curve (the ICC is not actually
linear). At least over this range, the ICC bends backward; x 
is an inferior good given these income levels and the current price.