# Dowling14.wxmx: Integrals & Economics

load(draw)$  set_draw_defaults(line_width=2, grid = [2,2], 
             background_color = light_gray,  draw_realpart=false)$ 
            fpprintprec:5$   ratprint:false$     kill(all)$

load ("Econ1.mac");

Sample use of functions in Econ1.mac

z : 3*x^2 - x*y + 2*y^2 - 4*x - 7*y + 12;
critPt : [ x =1,y =2];
Analyze (z, critPt)$
plotCP (z, critPt);

## Preface

This worksheet is one of a number of wxMaxima files available in the section
    Economic Analysis with Maxima
on my CSULB webpage.

We use Maxima to solve a few of the problems (and draw some of the plots) in Ch. 14 of the 
supplemental text: Introduction to  Mathematical Economics, 3rd ed, (Schaum's Outline 
Series), by Edward T. Dowling (1992, 2001), McGraw-Hill. This modestly priced text is a 
bargain with many worked out examples. You should compare the examples worked out 
"by hand" in this text with what we do using Maxima. Section numbers [x.y] refer to sections 
in Dowling's text.

We have slightly changed some of the symbols used in particular problems.

Ted Woollett
https://web.csulb.edu/~woollett/
Aug. 27, 2021

## References

D. Wade Hands, Introductory Mathematical Economics, 2nd ed, Oxford Univ. Press, 2004,
Ch. 1.

Chiang & Wainwright, Fundamental Methods of Mathematical Economics, 4th ed., 2005,
Ch. 14.

## Investment & Capital Formation [Dowling 14.6]

K(t) is the "time path of capital", the amount of capital accumulated at time t. 
The first derivative, dK(t)/dt, is the "rate of capital formation" = "rate of net investment flow
I(t) at time t".

     I(t) = dK(t)/dt

More briefly, I(t) = "net investment" (at time t). The units of I(t) will then be the units used for 
capital K  divided by the units used for time.

If we let [x] = units of x, and we assume [K] = thousands of $ and [t] = years, then 
[I] = [K]/[t] = thousands of $/year.

If we start with the time t' relation
      I(t') = dK(t')/dt', 
multiply both sides by dt' and sum (integrate) over values of t' from t' = t0 to t' = t > t0, 
we get integrate(I(t'),t',t0,t) = integrate (dK(t')/dt', t',t0,t) = K(t) - K(t0),
since   ∫dt' I(t') = ∫dt' (dK(t')/dt') = ∫dK(t') = K(tf) - K(ti), using tf for "t-final" and ti for "t-initial".

Hence,
K(t) = K(t0) + integrate (I(t'), t', t0, t) =  K(t0) +  ∫dt' I(t') |_t0^t

### Ex. 3, Chiang/Wainwright, p. 466

Given the net investment flow at time t: 
      I(t) = 3 t^(1/2) = 3 √t
let t0 = 0, K0 = K(t0) = K(0) = capital at time t = 0.
Then ΔK = K(t) - K0 = integrate (I(t'),t',0,t) = a "definite integral".
Calculate the increase of capital K over the time interval [0,t].

Here is an example of an "indefinite integral", since we don't include the limits on t; the 
result of an indefinite integral is an "antiderivative", differentiating the result once produces 
the original function.

integrate (sqrt(t), t);

diff (%, t);

grind(%)$

In this Ex. 3, we need to calculate a "definite integral", in which we supply the limits of 
integration. We let tp = t' be the dummy variable of integration here.
We define a Maxima function I(t).

assume (t > 0);
I(tt) := 3*sqrt(tt);
ΔK : integrate (I(tp),tp,0,t);

ΔK;

If we had not included the assume (t > 0) line above, Maxima would have asked for the
sign of the final value of tp, t. We could have then entered p; and the same answer would
have been produced.

### Ex. 4, Chiang/Wainwright, p. 467

If net investment I(t) = 1000 $/yr, what will be the "total net investment" (capital
formation) during one year, say from t = 0 to t = 1 yr?

ΔK : integrate (1000, tp, 0, 1);

In this problem, the units used for time t are years. The increase in capital K
in one year is thus $1000.

### Ex. 5, Chiang/Wainwright, p. 467

Using the rate of capital formation I(t) defined in Ex. 3,
  I(t) = 3 √t ,  with the units thousands of $/yr,
what is the increase in capital ΔK over the time interval [1,4], that is over the
second, third, and fourth years?

ΔK : integrate (I(tp),tp,1,4);

Thus K has increase by 14 thousand dollars over the time interval
[1 yr, 4 yr]

### Dowling Ex. 9, p 332

The rate of net investment is given by
  I(t) = 140 t^(3/4), 
and the initial stock of capital at t = 0 is 150. Determine K(t), the time path
of capital.

assume (t > 0);
K : 150 + integrate (140*tp^(3/4), tp, 0, t);

Maxima already remembered that we are assuming t > 0, so returned [redundant].

What is then the stock of capital at t = 5?

at (K, t = 5);

float(%);

You get a numerical answer in one line this way (for example):

at(K, t = 10),numer;

or this way:

float ( at(K, t = 10) );

If you want to turn the expression K into a Maxima function, say Kv(t), use 
two single quotes (') in front of K, as follows:

Kv(t) := ''K;

Kv(10),numer;

Kv(12),numer;

### Dowling Prob. 14.26

The rate of net investment I = 60 t^(1/3), and the capital stock at t = 1 is 85.
Find an expression for K(t) with t >= 1.

killAB()$
assume (t > 0);
I(tt) := 60*tt^(1/3);
K : 85 + integrate ( I(tp), tp, 1, t);

K : ratsimp (K);

at (K, t = 1);

Thus for t > 1 we can use 40 + 45 t^(4/3) for K.

float ( [at (K, t = 6),  at (K,t = 10) ] );

Here is the slope of curve K(t) at time t = 6:

I(6), numer;

Here is a plot of K(t) with a tangent line drawn (slope I(6) ) to the curve K(t) at time t = 6. 
Our plot makes use of the grid and background_color settings defined at the top of this 
worksheet.

wxdraw2d (xlabel = "t", ylabel = "K(t)",  key_pos = top_left, key = "K(t)",
    explicit (K, t, 1, 10), color = red, key = "tangent at t = 6",
    explicit (I(6)*(t - 6) + subst (6,t,K), t, 3, 9) , color = black, key = "",
    point_type = filled_circle, points ([6], [subst(6,t,K)]) )$

## Cost Functions TC, MC, VC, FC, ATC, AVC [Hands, Ch. 1]

### Short Run & Long Run Cost Functions

We roughly follow Hands, Ch. 1, p. 29 ff.

A firm's total-cost function TC defines the total cost of production of various levels of
output (y or Q). We can divide the total-cost function into variable costs VC which
depend on level of output and fixed costs FC (independent of ouput).
      TC(y) = VC(y) + FC.
"Short-run costs" involve both fixed and variable costs, while all costs are variable in
the long run. As production y increases, VC(y) increases to the point at which we can
ignore the relatively smaller fixed cost FC.

Consider a case in which FC = 100 and VC(y) = 4 y^2. Under these conditions, the
total-cost function is
   TC(y) = 4 y^2 + 100

killAB()$
TC : 4*y^2 + 100;
[at ( TC, y = 1), at (TC, y = 5)];

The total cost to produce y = 1 is $104 and the total cost to produce y = 5 is $200, etc.

In addition to total-costs (TC), economists pay attention to average and marginal costs.

### Average Cost Functions ATC, AVC, AFC

In the short run there are three average cost functions: average total cost (ATC), 
average variable cost (AVC), and average fixed cost (AFC), defined by
  ATC = TC(y)/y,    AVC = VC(y)/y,     AFC = FC/y

Note that since TC = VC + FC,   ATC = AVC + AFC

For our example, TC = 4 y^2 + 100,
      ATC = 4 y + 100/y,      AVC = 4 y,      AFC = 100/y.

Because FC does not depend on y, AFC gets arbitrarily large as y --> 0, and that limit is
not important in Economics.

### Marginal Cost Function MC

If we imagine that we can consider a limit in which the change in output Δy --> 0 in an 
approximate description of economic reality, we can define the "marginal cost function" 
(MC) as the first derivative of the total cost function with respect to output y.
    MC = d [TC(y)]/dy = diff (TC, y) in Maxima syntax.
Since TC = VC + FC, and since d(FC)/dy = 0, we have MC = d(VC)/dy.
In our example

VC : 4*y^2;
MC : diff (VC, y);

We get MC = 8 y. For this example, both MC (8 y) and AVC (4 y) are linear functions of y. 
Standard introductory economics texts usually display a U shape curve for MC and AVC, 
which would only show up if TC was a cubic function of production y, such as

       TC(y) = a y^3 + b y^2 + c y + d.

### Relating MC to ATC

Since ATC = TC/y, rearranging we get TC = y*ATC, so MC = dTC/dy = ATC + y*d(ATC)/dy.
Solving for d(ATC)/dy, we get,

          d(ATC)/dy = (MC - ATC)/y

The slope of the average total cost curve ATC is the left hand side of this equation.
If MC lies above ATC, MC > ATC, then the slope of ATC is positive and ATC is rising.
If MC lies below ATC, MC < ATC, then the slope of ATC is negative and ATC is declining.
If MC = ATC, then the slope of ATC is equal to zero.

When the average total cost (ATC) is rising then the marginal cost (MC) must lie above the
total average cost (MC > ATC).

When the average total cost (ATC) is falling then the marginal cost (MC) must lie below the
total average cost (MC < ATC).

When the average total cost is at a critical point (zero slope) then MC = ATC.

An identical relation exists between marginal cost (MC) and average variable cost (AVC).

### Finding Total Cost from Marginal Cost

This is Example 1 from Chiang & Wainwright, p. 465.

If the marginal cost (MC) of a firm is the following function of output,
    dC/dQ = 2*exp (0.2*Q)
and if the fixed cost Cf = 90, find the total cost function C(Q) for any value of Q >= 0.

By integrating the marginal cost (MC) over Q = 0 to some arbitrary positive value of Q,
and adding the fixed cost Cf, we get the total cost function C(Q).

In this example, we tell Maxima to treat Q as a positive number by using assume, and
we define the marginal cost MC in terms of a Maxima function (rather than a Maxima
expression). We use the Maxima function integrate with a dummy variable of integration qp.

killAB()$
assume (Q > 0);
MC(q) := 2*exp (0.2*q);
Cf : 90;
C : Cf + integrate (MC(qp), qp, 0, Q);

C : expand (C);

If we evaluate C for Q = 0 units, we get the fixed cost of production Cf = 90.

at (C, Q = 0);

Of course if we then take the first derivative of C(Q) wrt Q, we should recover the 
marginal-cost function we started with.

MC1 : diff (C, Q);

is (equal ( MC1, MC(Q) ) );

Here is a plot of C(Q) vs Q with a tangent line whose slope is the same as the
local slope of the curve C(Q) at the point of tangency Q = 95.

wxdraw2d (xlabel = "Q", ylabel = "C(Q)", key_pos = top_left, key = "C(Q)",
    explicit (C, Q, 85, 100), color = red, key = "tangent at Q = 95",
    explicit (MC(95)*(Q - 95) + subst (95, Q, C), Q, 92, 98) , color = black, key = "",
    point_type = filled_circle, points ([95], [subst(95, Q, C)]) )$

### Example: Average Cost vs Marginal Cost 

Given a total-cost function C(Q), the average-cost (AC) function is defined as
   AC = C(Q)/Q,  (for Q > 0),
the ratio of total cost at a particular value of Q > 0, divided by that particular value of Q.
This is the same at the average total cost ATC above.

Consider an example in Chiang & Wainwright, p. 160, in which
C(Q) = Q^3 - 12 Q^2 + 60 Q, an expression with zero fixed cost.

killAB()$
C : Q^3 - 12*Q^2 + 60*Q;
MC : diff (C,Q);
AC : expand (C/Q);

The curves MC and AC cross at Q = 6.

solve (MC = AC, Q);

Because the expression for AC is finite at Q = 0, we can draw a plot over the
range Q = [0, 10].

wxdraw2d (xlabel = "Q", ylabel = "MC, AC", xrange = [0,10], yrange = [0, 100],  
    key_pos = top_left, key = "MC", explicit (MC, Q, 0, 10), 
    color = red, key = "AC", explicit (AC, Q, 0, 10) )$

We proved the  general theorem above which states that 

  (a) the slope of the AC curve will be positive if and only if the MC curve lies 
           above the AC curve,
  
  (b) the slope of the AC curve will be negative if and only if the MC curve lies 
          below the AC curve,

  (c) the slope of the AC curve will be zero only at the point of intersection with
           the MC curve.

This theorem does NOT state that, when AC is negatively sloped, MC must also be
negatively sloped; it merely says that AC must exceed MC in that circumstance.

In our example, to the left of Q = 6, AC is declining, and thus MC lies below it.
To the right of Q = 6, AC is increasing and thus MC must lie above it.

### Dowling 14.27 

Find TC, AC, and VC if MC = 25 + 30 Q - 9 Q^2 and the fixed cost is 55.

killAB()$
assume (Q > 0);
MC(q) := 25 + 30*q - 9*q^2;
FC : 55;
TC : FC + integrate (MC(qp), qp, 0, Q);
AC : expand (TC/Q);
VC : TC - FC;

wxdraw2d (explicit (TC,Q,0,50))$

### Dowling 14.34

The marginal cost MC is 12 exp (Q/2) and the fixed cost FC is 36. 
Find the total cost function TC(Q). Let cc be the constant of integration.

killAB()$
FC : 36;
MC : 12*exp (Q/2);
TC : cc + integrate (MC, Q);

soln : solve (subst (Q = 0, TC) = FC, cc);

TC : at (TC, soln);

Note that the constant of integration cc, in this example, does not equal the fixed cost FC.

### Dowling 14.35, modified.

Let MC = 16.3 exp(0.48 Q) and FC = 78.4. Find TC(Q).

killAB()$
FC : 78.4;
MC : 16.3*exp (0.48*Q);
TC : cc + integrate (MC, Q);

soln : solve (subst (Q = 0, TC) = FC, cc), numer;

TC : at (TC, soln);

## Total and Marginal Revenue

### Find Marginal Revenue from a Demand Curve [Hands, Ch. 1]

Consider this example from Hands, Ch. 1, p. 19.

Assume a linear demand curve Q = - P + 5, where P is the market price per unit of good 
and Q is the quantity of units of that good. If Q = 1 unit means one thousand Toyota cars, 
then P is the market price per one thousand Toyota cars.

A linear demand curve is not "economics-realistic" as Q --> 0.

The "inverse demand curve" means P as a function of Q, P = 5 - Q.

The total revenue associated with each level of output Q is simply the price per unit (P) 
times the number of units (Q):

       TR = TR(Q) = P Q = (5 - Q ) Q = 5 Q - Q^2

The marginal Revenue (MR) is the first derivative of the total revenue with respect to Q.
  MR = d(TR)/dQ = dTR/dQ  = 5 - 2 Q.
Let MR0 be the value of Q for which MR = 0.
An economist would label the first plot "Demand Curve" since economists have the habit
of breaking the normal convention of (dependent variable=yaxis, independent variable
= xaxis) in the case of a plot involving prices as the independent variable.

killAB()$
TR : 5*Q - Q^2;
MR : diff (TR,Q);
MR0 : solve (MR, Q);
TRmax : at (TR, MR0);
MR0 : rhs (MR0[1]);
MRmin : at (MR, Q = 5);
wxdraw2d (xlabel = "Q", ylabel = "P", title = "Inverse Demand Curve",
     key = "P = 5 - Q",   explicit (5 - Q, Q, 0, 5))$
wxdraw2d (xlabel = "Q", ylabel = "TR, MR", title = "Total Revenue and Marginal Revenue",
     yrange = [MRmin, 7],  key_pos = bottom_left,   key = "TR = 5*Q - Q^2",
    color = red,  explicit (TR, Q, 0,5), color = purple,
    key = "MR = 5 - 2*Q", explicit (MR, Q, 0, 5), color = black, key = "",
    line_width = 1, explicit (0, Q, 0, 5), parametric (MR0, yy, yy, MRmin, TRmax) )$

float (TRmax);

When the price per unit is 4, the quantity demanded is 1 unit and the total revenue TR is 4.
 At the lower price P = 1 the quantity demanded in 4 units and the total revenue TR is again
4. We expect, from human nature, that the lower the price per unit, the more units will
be sold.

Between the low Q and high price region and the high Q but low price region there is
a "sweet spot" for maximum revenue, which occurs at the value of Q where MR passes 
from positive to negative.

### Dowling 14.29, TR & P(Q) from MR

Given MR = 60  - 2 Q - 2 Q^2, find the total revenue TR and the inverse demand function
P(Q).

Since when Q = 0, TR = 0 also (by definition), we just need to integrate MR from Q = 0 to
some arbitrary positive Q to find TR(Q). We then can use TR(Q) = P(Q) Q to solve for
P(Q), the inverse demand function. It is then clear that the average revenue function
AR(Q) = TR(Q)/Q is the same as the inverse demand function P(Q).

killAB()$
MR(q) := 60 - 2*q - 2*q^2;
assume (Q > 0);
TR : integrate (MR(q), q, 0, Q), expand;
P : expand (TR/Q);

For what value of Q > 0 is TR equal to its maximum?

solns : solve (MR(Q), Q);

The only physical solution is Q = 5 > 0.

soln : rest (solns, 1);

MR0 : 5;

TRmax : at (TR, soln), numer;

Pmax : at (P, soln), numer;

Pmin : at (P, Q = 10), numer;

MRmin : at (MR(Q), Q = 10);

solns : solve (P, Q), numer;

soln : rest (solns,1);

QP0 : at (Q, soln);

wxdraw2d (xlabel = "Q", ylabel = "P", title = "Inverse Demand Curve P(Q)",
     key = "P = 60 - Q - 2*Q^2/3",   explicit (P, Q, 0, 10), color = black, key = "",
    line_width = 1, explicit (0, Q, 0, 10), explicit (Pmax, Q, 0, 5),
    parametric (5, yy, yy, Pmin, Pmax), parametric (QP0, yy, yy, Pmin, 0))$

wxdraw2d (xlabel = "Q", ylabel = "TR, MR", title = "Total Revenue and Marginal Revenue",
     yrange = [MRmin, 200],  key_pos = bottom_left,   key = "TR = 60*Q - Q^2 - 2*Q^3/3",
    color = red,  explicit (TR, Q, 0, 10),  color = purple,
    key = "MR = 60 - 2*Q - 2*Q^2", explicit (MR, Q, 0, 10), color = black, key = "",
    line_width = 1, explicit (0, Q, 0, 10), parametric (MR0, yy, yy, MRmin, TRmax),
    parametric (QP0, yy, yy, MRmin, 0))$

The total revenue reaches its maximum value just as the marginal revenue passes
from positive to negative (the slope of the TR(Q) curve is zero at that point). The total 
revenue continues to increase as long as the marginal revenue remains > 0.

## Consumption Function, Marginal Propensity to Consume

In Dowling, Ch.2, there is a discussion of national income Y determination models, 
such as Y  = C + I + G + (X - Z), with C = consumption, I = investment, G = government
spending, X = exports, Z = imports. 
Any one of the terms on the right hand side can have a component which is a function
of national income Y, and which will hence influence the equilibrium value of Y.

In particular, for example, we can have C = C0 + b Y, where C0 is independent of national
income Y, and b is the marginal propensity to consume MPC, the first derivative of
consumption with respect to Y. However, b itself may be a function of Y.

### Dowling 14.32,  Find Consumption Function from MPC and C0

Find the consumption function C(Y) = C0 + b g(Y)  if C0 = 45, and if
MPC = 0.6 + 0.1/Y^(1/3) = first derivative of C(Y) wrt Y. We use an indefinite integral
(anti-derivative) and add a constant c which can be adjusted to match the conditions
at the point Y = 0.

killAB()$
MPC : 0.6 + 0.1/Y^(1/3);
C : c +  integrate (MPC, Y) ;

The first derivative of the above should equal MPC. Maxima treats c as a constant unless
told otherwise using depends.

diff (C, Y);

soln : solve ( subst (Y=0, C) = 45, c);

C : at (C, soln);

Thus C(Y) = 45 + 0.6 Y + 0.15 Y^(2/3).

## Savings Function and Marginal Propensity to Save

Reference: Hands, Ch. 3, pp 96-97.

In a closed economy (no foreign trade) the aggregate expenditure on goods is
   C + I + G
where C = (personal) consumption expenditure, I = investment expenditure, 
G = government spending.

The aggregate income generated by the production of these goods is
   C + S + T
where S = savings and T = taxes.

For the goods market to be in equilibrium, expenditure = income, so
   C + I + G = C + S + T
or
  S = I + (G - T).
National savings = investment - deficit, where 
D = (G - T) = government spending - tax receipts = deficit.

In the IS-LM model, the savings function S depends on both the level of national income
(GDP) Y and the rate of interest r: S = S (Y,r), with the standard economic assumptions
that ∂S/∂Y > 0 and ∂S/∂r > 0.

### Dowling 14.33 Marginal Propensity to Save MPS and S(Y)

Suppose the marginal propensity to save MPS is
   ∂S/∂Y  = 0.5 - 0.2/Y^(1/2) and when Y = 25, S = -3.5.
Find S(Y).

killAB()$
MPS : 0.5 - 0.2/Y^(1/2);
S : c +  integrate (MPS, Y);

soln : solve (subst (Y = 25,S) = -3.5, c);

S : at (S, soln);

at (S, Y = 25);

Thus the savings function is 
  S(Y) = 0.5 Y - 0.4 Y^(1/2) - 14.