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

# Firm and Industry Supply 
in the Short-run

This chapter begins by combining the implications of the firm's 
output with the implications for revenue. We assume that the firm's 
goal is to maximize profit, defined as revenue minus cost.

## An Illustrative Cost Function

To illustrate the nature of profit maximization, we use a cubic cost 
function, which we build in a series of steps. First specify an arbitrary
value x=x0 and a value for the average variable avc0=a0 when x=x0.
(a is the coefficient of x in the expression stc = c*x^3+b*x^2+a*x.
For this expression, avc = stc/x = c*x^2 + b*x + a.)

The first input line below defines avc and stc}. The 
second input line determines the first and second derivatives 
of stc (the marginal cost and its slope). The table shows the
resulting output.

Note that the coefficient of x^3 takes the value c = b*x0^2. 
Therefore the stc is a function of a and b, along with F, the 
per-period fixed cost.

A separate output item results from finding the value of x
at which the marginal cost curve reaches it minium point. For
the cubic expression, this quantity is x = (2/3)*x0.

avc:expand(a+b*(x-x0)^2)$    stc:expand(F+avc*x)$
smc:diff(stc,x)$                diff_smc:diff(stc, x, 2)$
matrix(["avc =",avc],["stc =",stc],["smc =",smc],
 ["diff_smc =",diff_smc]);  solnmin:solve(diff_smc,x);

Economic theory dictates that that marginal cost cannot
be negative. We impose this condition by asserting, arbitrarily,
that the minimum value of mc is a/4. The minimum mc value
is determined by substitution (2/3)*x0 for x in the smc expression,
setting the result equal to a/4, and solving for b. 

solnb: solve(subst(solnmin[1],smc)=a/4,b);

Now all short-run cost functions can be expressed in terms
of the parameters, a and F, and the arbitrarily-specified value
of x, x0.

avc(x,x0,a)   := ''(subst(solnb[1],avc));
stc(x,x0,a,F) := ''(subst(solnb[1],stc));
sac(x,x0,a,F) := ''(expand(subst(solnb[1],stc/x)));
smc(x,x0,a)   := ''(expand(subst(solnb[1],smc)));

We can specify the values, as we do below, or we could have
specified the minimum value of sac when x = x0. To reduce
the number of paramters, we define F0 = a0*x0/2. That is,
per-unit fixed cost is one-half of average variable cost at the 
minimum point on the avc curve. This definition can be replaced
with a given value of F0.

[x0,a0]:[50,30]$ F0:a0*x0/2$  
wxdraw2d(xlabel="x",ylabel="$ per unit",
 user_preamble="set key center right",
 yrange=[0,1.5*(a0+F0/x0)], line_width=2,
 key="sac", explicit(sac(x,x0,a0,F0),x,0,2*x0),
 color = red, key="avc",explicit(avc(x,x0,a0),x,0,2*x0),
 color=black, key="smc",explicit(smc(x,x0,a0),x,0,2*x0),
 key="afc",color=orange,explicit(F0/x,x,0.1,2*x0),
 dimensions=[480,480])$

## Selecting a Quantity

We assume that the firm selects the quantity that generates maximum
profits.

### A General Statement

The value of x that yields maximum profits is the one at which
d(Profit)/dx = 0. The next cell provides a general statement of 
the condition that must pertain in order to satisfy this condition,
given the definition that Profit = Revenue - Cost and assuming 
that Revenue and Cost are both affected by x.

depends([Revenue,Cost],x)$ Profit:Revenue-Cost$   
solve(diff(Profit,x)=0,x);

We add a section assumption, that each unit is sold at the same
price. Chapter 13 examines some implications of relaxing this
assumption. Given this assumption Profit = p*x - Cost.

### The Price-taking Firm

Suppose that p is unrelated to x. Then selling an additional
unit of x generates addition revenue of p: marginal revenue 
is p. In that case, the x that yields maximum Profit is the 
one at whicch d(Cost)/dx = p.

Profit:p*x-Cost$   solve(diff(Profit,x)=0,x);

### The Price Searching Firm

If x affects p, then the derivative of Revenue with respect to
x is p + dp/dx. Presumably, the demand curve for the firm's 
product is downward-sloping, so dp/dx < 0, implying that 
marginal revenue, p + x*dp/dx is less than price.

depends(p,x)$  Profit:p*x-Cost$ diff(Profit,x);

### Illustration

We use a linear demand curve for the firm's product. To specifies its
parameters, fix the quantity when p = 0 at x = 3*x0, and at x = x0  set the height of 
the demand curve at 1.2 times the short-run average cost. 
These selected ensure that the firm can earn a profit.

p(x,e,f):= e+f*x;    solnp1:solve([p(3*x0,e,f)=0, 
    p(x0,e,f) = 1.2*sac(x0,x0,a0,F0)],[e, f])[1];

Binds these parameter values to the names e1 and f1. 

[e1,f1]:[rhs(solnp1[1]),rhs(solnp1[2])]$

Total revenue = p(x,e,f)*x = f*x^2 + e*x, so mr = 2*f*x + e, and 
profit is the cubic function shown below.

radcan(p(x,e,f)*x);
mr(x,e,f):=''(diff(x*p(x,e,f),x));
profit(x,e,f,a,F):=''(expand(x*(p(x,e,f)-sac(x,x0,a,F))));

The next cell shows the relevant revenue information for this parameter set.

expand(float([p(x,e1,f1),x*p(x,e1,f1),mr(x,e1,f1)]))$
matrix(["Demand","Total Revenue","Marginal Revenue"],%);

Setting mr = smc yields two values of x. At each value the slope of the 
profit function is zero. At the first value generates minimum profit; the
second generates maximum profit.

solnq1:float(solve(mr(x,e1,f1)=smc(x,x0,a0),x));

To check the second-order condtions create expressions for the first and second
derivatives of the profit function with respect to x and evaluate these at the two
values of x that are defined above.

[diff1: diff(profit(x,e1,f1,a0,F0),x),
 diff2: diff(profit(x,e1,f1,a0,F0),x,2)];
minprofitvalues: [subst(solnq1[1],diff1),
    subst(solnq1[1],diff2)];
maxprofitvalues: [subst(solnq1[2],diff1),
    subst(solnq1[2],diff2)];

The table show thes profit levels associated with the profit-minimizing value 
of x and the profit-maximizing value of x, the latter of which is assigned the
name x1.

[profit(rhs(solnq1[1]),e1,f1,a0,F0), profit(rhs(
  solnq1[2]),e1,f1,a0,F0),x1:rhs(solnq1[2])]$  matrix(
  ["Min Profit","Max Profit","Profit Maximizing x"],%);

The table below shows relevant revenue, cost, and profit data for a list of 
output levels, values of which are multiples of x1. The fifth row contains values
for x1. 

fpprintprec:3$   xlist:makelist(2*i*x1/10, i, 1, 8)$
plist:p(xlist,e1,f1)$    trlist:xlist*plist$
aclist:sac(xlist, x0,a0,F0)$  tclist:xlist*aclist$  
mrlist:mr(xlist,e1,f1)$  proflist:trlist-tclist$
mclist:smc(xlist, x0, a0)$ names : matrix(
  ["x","p=ar","tr","sac","stc","profit","mr","smc"])$
numbers:transpose(matrix(xlist,plist,trlist,aclist, 
     tclist,proflist,mrlist,mclist))$
addrow(names,numbers);   fpprintprec:5$

The graph below confirms the results above.  Thevertical range is
extended slightly beyond the one used in the text. It now shows 
the marginal cost and marginal revenue values when x = 4.141.

wxdraw2d(user_preamble="set key bottom", 
 xlabel="x", ylabel="$ per unit", 
 yrange=[0,1.25*p(0,e1,f1)],line_width=2,key="p",
 explicit(p(x,e1,f1),x,0,2*x1),color=gray,key="mr", 
 explicit(mr(x,e1,f1),x,0,2*x1),color=red,key="avc",
 explicit(avc(x,x0,a0), x,0,2*x1),color=orange,key="sac",
 explicit(sac(x,x0,a0,F0),x,0,2*x1),color=black,key="smc",
 explicit(smc(x,x0,a0),x,0,2*x1), dimensions=[480,480])$

The example below shows the same firm facing a reduced demand curve. 
The curve is shifted so that, at x = x0, its height is halfway between avc and sac.
Thus variable costs can be covered, but not all fixed costs can be recovered. 

solnp2:solve(
 [p(4*x0,e,f)=0,p(x0,e,f)= (sac(x0,x0,a0,F0)+avc(x0,x0,a0))/2],
 [e,f])$
[e2,f2]:[rhs(solnp2[1][1]),rhs(solnp2[1][2])]$
matrix(["e1","e2"],[float(e1),float(e2)]);

TeX: The graph shows that the demand curve lies below
$sac$ for all $x$. Therefore, the firm cannot earn a profit
in the short run. It can, however, cover its variable cost, 
partially offsetting the per-period fixed cost.

wxdraw2d(user_preamble="set key bottom",
 xlabel="x",ylabel="$ per unit",
 yrange=[0,1.1*p(0,e2,f2)],line_width=2,key="p",
 explicit(p(x,e2,f2),x,0,2*x1),color=gray,key="mr",
 explicit(mr(x,e2,f2),x,0,2*x1),color=red,key="avc",
 explicit(avc(x,x0,a0),x,0,2*x1),color=orange,key="sac",
 explicit(sac(x,x0,a0,F0),x,0,2*x1),
 color=black,key="smc",explicit(smc(x,x0,a0),x,0,2*x1))$

Ouput level x = 49.4 leads to a maximum profit level, which is a loss. This loss is 
less than the firm would incur at x = 0, which is F = 2000.

solnprof2:float(solve(mr(x,e2,f2)=smc(x,x0,a0),x))$
x2 : rhs(solnprof2[2])$
matrix(["x2","profit"],[x2, profit(x2,e2,f2,a0,F0)]);

The next table below confirms that a loss results from any
output level but that the loss is minimized when x = 49.4, where 
marginal revenue equals marginal cost.

fpprintprec:3$ xlist2:makelist(2*i*x2/10,i,1,8)$
plist2:p(xlist2,e2,f2)$  trlist2:xlist2*plist2$
aclist2:sac(xlist2,x0,a0,F0)$  tclist2:xlist2*aclist2$
mrlist2:mr(xlist2,e2,f2)$  proflist2:trlist2-tclist2$
mclist2:smc(xlist2,x0,a0)$  names: matrix(
  ["x","p","tr","sac","stc","profits","mr","smc"])$
numbers:transpose(matrix(xlist2,plist2,trlist2,aclist2,
  tclist2,proflist2,mrlist2,mclist2))$  
addrow(names,numbers); fpprintprec:5$

## The Price-Taking Firm in the Short Run

The price for which the price-taking firm sells its product is determined 
by the market and is not affected by x.  

### Market Elasticity, Firm Size, 
and the Firm's Marginal Revenue

Even if a firm's output is large enough to have some effect on price,
the implied difference between the marginal revenue from changing
x and the price can be slight. The ratio of marginal revenue price is
(1 + Ep)/Ep, where Ep (a negative number) is the price elasticity of 
demand for the firm's product. We see below that Ep is probably a 
large negative number of most firms. Also, we can see inspection,
that as Ep becomes an increasingly large negative number, the 
ratio above approaches 1. That is mr approaches p.

The text shows that if the firm sees itself as taking the market 
demand as given and the supply of other firms as given, then the
demand for its product is a residual: x = X - xo, where x is the firm's
quantity, X is the quantity demanded, and xo is the quantity supplied
by other firms.

From this identity, we can deduce that Ef = Em/s + Eo*(1-s)/s, where
Ef is the elasticity of demand for the firm's product, Em is the elasticity
of demand and the market level, and Eo is the elasticity of supply from
other firms. Both Ef and Em are negative; Eo is positive. The firm's 
share of market output is s = x/X.

Ef(Em,Eo,s):=Em/s-Eo*(1-s)/s;

In the table below, "Less Elastic" means Em = -0.5 and 
Eo = 0.25. "More Elastic" means Em = -1.5 and Eo = 0.75.
(In later chapters, we argue that even Eo = 0.75 is probably
too small.)

Unless the firm is large relative to the market, the difference
between mr and p is rather small. The first row could 
correspond to a market in which each of 20 firms had an
equal market share. In such a case, mr > 0.9*p. Even when
the number of firms is 10, mr/p is near to or above 0.9.

slist:makelist(i*.05,i,1,6)$ 
Ef1list:Ef(-0.5,0.25,slist)$  mr1list:1 + 1/Ef1list$         
Ef2list:Ef(-1.5,0.75,slist)$  mr2list:1 + 1/Ef2list$
numbers:transpose(matrix(slist,Ef1list,mr1list,Ef2list,
  mr2list))$    names : matrix(["s", "Less Elastic", 
"mr/p, low","More Elastic", "mr/p, high"])$
addrow(names, numbers);

### Determining Quantity

The input group below determines the value of x
for a price-taking firm with the cost function used above. 

The first output line shows the values of x. Only the second
is positive, so this is the relevant relationship. Inspection 
shows that if p < 15/2, then the output is imaginary.

The second output line shows that this value, 15/2, is the 
minimum point on the firm's smc curve. Look at the graphs
above to realize that if p = 15/2, then p < avc, so the firm
will not be in business.

[solnpt : solve(p-smc(x,x0,a0),x)]; 
smc(x0*2/3,x0,a0);

Define a profit function ptprofit(p) and a supply 
curve x(p) for this price-taking firm. Unlike the price-searching
firm, which must determine both price and quantity together, this
firm has a supply curves, which expresses quantity in terms of an 
externally determined price.

ptprofit(p):=''(ratsimp(subst(solnpt[2],p*x-stc(x,x0,a0,F0))));
x(p):=''(rhs(solnpt[2]));

The next table shows the profit-maximizing quantity
and the profit level at each of a set of prices.

plist:float(makelist(i*a0/4,i,1,10))$  xlist:
float(x(plist))$ ptprofitlist:float(ptprofit(plist))$
names:matrix(["Price","Quantity","Profit"])$
numbers:transpose(matrix(plist,xlist,ptprofitlist))$
addrow(names,numbers);

The graph shows the firm's short-run supply curve, the segment 
of the firm's short-run marginal cost curve that lies above the 
average variable cost curve.

wxdraw2d(user_preamble="set key bottom",xlabel="x",
 ylabel="$ per unit",yrange= [0, 1.1*p(0,e2,f2)],
 key ="p = avc", explicit(avc(x0,x0,a0),x,0,x0), 
 key="avc",explicit(avc(x,x0,a0),x,0, 2*x1),line_width
 =2,key="sac",explicit(sac(x,x0,a0,F0),x,0,2*x1),
 color=gray40,key="smc",explicit(smc(x,x0,a0),x,0,2*x1), 
 key="supply",line_width=3,color=black,
 explicit(smc(x,x0,a0),x,x0,2*x1)   )$

### The Firm and the Industry

In the short-run the number of firms is constant. Therefore, the 
logic of the relationship between firms' supply curves and the industry 
supply curve is simple: at each price the quantity supplied in the market 
is the sum of the quantities produced by the individual firms. That is, 
the industry supply curve is the result of a horizontal summation
of the firms' supply curves.

In the special case of n identical firms, the industry supply is n*x(p).

define(X(p,n), n*x(p)); /* or X(p, n) := ''(n*x(p)); */ end;

The firm and industry supply curves appear below. The
two supply curves are identical except for scale.

n0:100$   
firmsupply:gr2d(title="Firm Supply",
 yrange=[0,2*a0],xlabel="x",ylabel="$ per unit",
 implicit(x =x(p), x, x0/2, 1.5*x0, p, a0, 3*a0))$

industrysupply:gr2d(title="Industry Supply",
 yrange=[0,2*a0],xlabel= "X", ylabel="$ per unit",
 xtics=2000,line_width=2,
 implicit(X =X(p, n0), X, 100*x0/2,150*x0,p,a0,3*a0))$

wxdraw(firmsupply, industrysupply, columns=2)$

### Demand and Equilibrium

Adding a market demand curve completes the model. We use a 
constant elasticity demand curve X = A*P^Em. We solve for the case 
in which p = 1.5*0$ at X = 5000 (both 1.5 and 5000 are arbitrarily 
selected) in order to determine A's value.  The initial functional expression 
X = A*p^Em is replaced in Maxima's memory by the expression 
X = A0*p^Em0. We could have left the more general expression, but
we do not explore shifts at this point.

Em0:-1.5$   Xd(p,Em):=A*p^Em;  solve(Xd(1.5*a0,Em0)=
  5000,A)$   A0:rhs(%[1]);  Xd(p):=A0*p^Em0;

We use find_root( ) to determine the equilibrium price.
Once price is deermined, the market supply curve  

peq0:find_root(Xd(p)-X(p,n0),p,a0,3*a0);
 Xeq0:float(X(peq0,n0));
matrix(["Equilibrium Price =",peq0],
  ["Equilibrium Quantity =",Xeq0]);

TeX: The graphs below replicate the ones above, but add 
three items: the demand curve, horizontal lines to indicate the
equilibrium price, and a vertical line to indicate the 
equilibrium quantity.  The horizontal line in the left-hand 
panel corresponds to the demand curve for the firm's product.

firmx: gr2d(title="Firm Supply and Demand",
  user_preamble="set key bottom",
  yrange=[0,2*a0],xlabel="x",ylabel="$ per unit",
  line_width=2, key="Firm Supply",
  implicit(x=x(p), x, x0/2, 1.5*x0, p, a0, 3*a0), 
  color=red,  key="Firm Demand",
  explicit(peq0,x,x0/2,1.5*x0) )$

industryX : gr2d(title="Market Supply and Demand",
 user_preamble="set key bottom",
 yrange=[0, 2*a0],xlabel="x",ylabel="$ per unit",
 xtics=2000,line_type=dots,points_joined=true, 
 color=black,  points([ [Xeq0,0],[Xeq0,peq0]]),
 points([ [n0*x0/2, peq0], [Xeq0, peq0] ]), 
 line_type=solid,line_width=2, color=blue,key="Market Demand",
 implicit(X=X(p,n0), X, 100*x0/2, 150*x0,p,a0,3*a0),color=red,
 key="Market Supply", 
 implicit(Xd(p)=X,X,100*x0/2,1.5*n0*x0,p,a0,3*a0))$

wxdraw(firmx, industryX, columns=2, dimensions = [600,400])$