# Demand and Supply

## Demand and Supply: Basics

Define the demand and supply curves in terms of shift
parameters (A and B) and elasticities (a and b). Use
functional notation, like this XD(p,A,a):= ... .

/*Input. Execute (ctrl-enter) for results */
kill(all)$
XD(p,A,a) := A*p^a; XS(p,B,b) := B*p^b;

Determine the functions for the demand and supply curves
if A=1200, a=-0.5, B=50, and b = 1.5.

/*Input. Execute (ctrl-enter) for results */
[XD(p,1200,-0.5), XS(p,50,1.5)];

Determine the quantity demanded and the quantity supplied 
given the parameters above and p = 2.5.

/*Input. Execute (ctrl-enter) for results */
[XD(2.5,1200,-0.5), XS(2.5,50,1.5)];

Use find_root to approximate the equilibrium price given
the parameters above. Begin the price range over which 
find_root is to search at a small positive number, like 0.001,
because find_root cannot evaluate the expression when p = 0.
Name this price peq0.

/*Input. Execute (ctrl-enter) for results */
peq0: find_root(XD(p, 1200,-0.5)=XS(p,50,1.5),p,0.001,10);

Confirm that p = peq0 results in quantity demanded = quantity 
supplied. Note: You can copy %i3 or %i4 above and replace p or
2.5 with peq0. Name one of the two values Xeq0.

/*Input. Execute (ctrl-enter) for results */
[XD(peq0,1200,-0.5), Xeq0:XS(peq0,50,1.5)];

## Inverse Demand and Supply Curves

Invert the demand and supply curves and create the inverse 
demand curve pD(X,A,a) := (...). Determine the expression.
Create a similar functional expression for the supply curve,
and label it xS(X,B,b).

/*Input. Execute (ctrl-enter) for results */
assume(A>0,B>0,X>0,a<0,b>0)$
declare(a,noninteger, b,noninteger)$
solve(XD(p,A,a)=X,p); pD(X,A,a):=''(rhs(%[1]));
solve(XS(p,B,b)=X,p)$ rhs(%[1])$ pS(X,B,b):= ''%;

Define a list of parameters: A0=1200, a0=-0.5, B0=50, and b0=1.5. 

/*Input. Execute (ctrl-enter) for results */
[A0,a0,B0,b0]:[1200,-0.5,50,1.5]$

Create a list of six X values that range from 0.25*Xeq0 to 1.5*Xeq0
in increments of 0.25*Xeq0. Confirm that the demand price equals the
supply price at X = Xeq0.

/*Input. Execute (ctrl-enter) for results */
Xlist: makelist(Xeq0*.25*i,i,1,6)$
pDlist: pD(Xlist,A0,a0)$
pSlist: pS(Xlist,B0,b0)$
/* The following is not required to answer the question.*/
Table: transpose(matrix(Xlist,pDlist,pSlist))$
addrow(matrix(["X", "pD", "pS"]),Table);

Draw the inverse demand and supply curves using these parameters. Label
the quantity axis "X" and the price axis "$ per unit". Graph the functions 
for values of X between 0 and 1000. Label the inverse demand curve "Demand" and 
the inverse supply curve "Supply". Make the supply curve black. 
Set yrange=[0,10]. 

Be aware that Maxima is case sensitive: price is p, not P; market quantity is
X, not x.

/*Input. Execute (ctrl-enter) for results */
wxdraw2d(xlabel="X",ylabel="$ per unit", yrange=[0,10],
key="Demand", explicit(pD(X,A0,a0),X,0,1000), color=black,
key="Supply", explicit(pS(X,B0,b0),X,0,1000)
/*
The rest of the commands are not required. They use the
points command to point to the equilibrium price and 
quantity*/ 
, points_joined=true, line_type=dots,
points([[0,peq0],[XD(peq0,A0,a0),peq0],[XD(peq0,A0,a0),0]  ])

)$

## Disequilibrium 

Follow the example above to graph the effect of a price floor,
with p = 6.

/*Input. Execute (ctrl-enter) for results */
wxdraw2d(xlabel="X",ylabel="$ per unit", yrange=[0,10],
key="Demand", explicit(pD(X,A0,a0),X,0,1000), color=black,
key="Supply", explicit(pS(X,B0,b0),X,0,1000) , 
points_joined=true, line_type=dots,
points([[0,6],[XD(6,A0,a0),6],[XS(6,B0,b0),6]  ])
)$

Determine the quantity demanded, the quantity supplied, and the 
size of the excess demand that the graph indicates. Set the 
floating-point print precision to 5.

/*Input. Execute (ctrl-enter) for results */
fpprintprec:5$
[XD(A0,a0,6),XS(B0,b0,6),XS(6,B0,b0)-XD(6,A0,a0)];
/*The following is not required, but shows how matrix can improve
the appearance of the output*/
matrix(["XD if p=6","XS if p=6","XS - XD if p=6"],
  [XD(6,A0,a0),XS(6,B0,b0),XS(6,B0,b0)-XD(6,A0,a0)]);

Graph the effect of a price ceiling, with p = 4.

/*Input. Execute (ctrl-enter) for results */
wxdraw2d(xlabel="X",ylabel="$ per unit", yrange=[0,10],
key="Demand", explicit(pD(X,A0,a0),X,0,1000), color=black,
key="Supply", explicit(pS(X,B0,b0),X,0,1000) , 
points_joined=true, line_type=dots,
points([[0,4],[XD(4,A0,a0),4],[XS(4,B0,b0),4]  ])
)$

Determine the quantity demanded, the quantity supplied, and the 
size of the excess supply that the graph indicates. 

/*Input. Execute (ctrl-enter) for results */
[XD(A0,a0,4),XS(B0,b0,4),XS(4,B0,b0)-XD(4,A0,a0)];
/*The following is not required, but shows how matrix can improve
the appearance of the output*/
matrix(["XD if p=4","XS if p=4","XD - XS if p=4"],
  [XD(4,A0,a0),XS(4,B0,b0),XD(4,A0,a0)-XS(4,B0,b0)]);

## Sales Tax

Impose a tax t = 1 on either the sale or the purchase of this good.
Either way, the price paid is 1 more than the price received. Enter
this information into find_root and determine the post-tax quantity.
Label this Xeq1 and determine the quantity reduction due to the tax.

/*Input. Execute (ctrl-enter) for results */
Xeq1:find_root(pD(X,A0,a0)-pS(X,B0,b0)=1, X,.001,1000)$
Xeq0-Xeq1$
/*The following command is not required to answer the question.*/
print("The post-tax quantity is ",Xeq1," which is ",Xeq0-Xeq1,
" less than the equilibrium with no tax.")$

Determine the effect of the tax on the prices that consumers pay and that
sellers receive. Given the elasticities, which of these prices do you 
expect to change more? 

/*Input. Execute (ctrl-enter) for results */
[pD(Xeq1,A0,a0),pS(500,B0,b0)];
print("The price paid by consumers rises from ",peq0,"to ",pD(Xeq1,A0,a0))$
print("The price received by sellers falls from ",
        peq0,"to ",pS(Xeq1,B0,b0))$

Suppose that this tax is nominally placed on sellers. Copy the first graph above
and add the new tax-laden inverse supply curve to the graph.

wxdraw2d(xlabel="X",ylabel="$ per unit", yrange=[0,10],
key="Demand", explicit(pD(X,A0,a0),X,0,1000), color=black,
key="Supply", explicit(pS(X,B0,b0),X,0,1000), key="New Supply",
color=green, explicit(pS(X,B0,b0)+1,X,0,1000)  )$

## Excise Subsidy

Suppose that 20 percent of the price of this good is to be paid by taxpayers,
so that the purchase price is 0.8 times the sales price. Use find_root to 
determine the equilibrium quantity, and assign the name Xeq2 to that quantity.

/*Input. Execute (ctrl-enter) for results */
Xeq2: find_root(pD(X,A0,a0)/pS(X,B0,b0) = 0.8, X, 1, 1000);

Determine the price paid and the price received at this new equilibrium.

/*Input. Execute (ctrl-enter) for results */
[pD(Xeq2,A0,a0),pS(Xeq2,B0,b0),pD(Xeq0,A0,a0)];

Suppose that the subsidy is nominally paid to buyers. Copy the first
graph and add the post-subsidy demand curve.

/*Input. Execute (ctrl-enter) for results */
wxdraw2d(xlabel="X",ylabel="$ per unit", yrange=[0,10],
 line_width=2, key="Demand", explicit(pD(X,A0,a0),X,0,1000), 
 color=red,key="Supply", explicit(pS(X,B0,b0),X,0,1000), 
 key="New Demand",color=black, explicit(pD(X,A0,a0)/0.8,X,0,1000)  )$