# Multivariable Functions in Econ.,  Part II

load(draw)$  set_draw_defaults(line_width=2, grid = [2,2], point_type = filled_circle,
          head_type = 'nofilled, head_angle = 20, head_length = 0.5,
             background_color = light_gray,  draw_realpart=false)$     
 fpprintprec : 5$  ratprint : false$

load ("Econ1.mac");

## Preface

Dowling06.wxmx is one of a number of wxMaxima  and pdf 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. 6 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. Problems in
this worksheet make use of some of the economic analysis functions defined in the
software file Econ1.mac.

Ted Woollett
https://web.csulb.edu/~woollett/
May 6, 2022

## References

Introduction to  Mathematical Economics, 3rd ed, (Schaum's Outline Series), 
by Edward T. Dowling (1992, 2001), McGraw-Hill,

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

Mathematical Economics, 2nd. ed., Jeffrey Baldani, James Bradfield, and Robert W. 
Turner, 2005, Thomson.

Macroeconomics, 5th ed., Olivier Blanchard, 2011, Prentice Hall.

Fundamental Methods of Mathematical Economics, 4th ed., Alpha C. Chiang and Kevin
 Wainwright, 2005, McGraw Hill.

(IEA) Introduction to Economic Analysis, R. Preston McAfee, Tracy Lewis, Donald J. Dale,
 2009,
read on web:   https://saylordotorg.github.io/text_introduction-to-economic-analysis/
get pdf:  https://mcafee.cc/Papers/Introecon/ieav21.pdf

## Marginal Productivity  [6.1]

The "marginal product of capital" MPK is the derivative of the output Q wrt units of 
capital K,   MPK = ∂Q/∂K.

The "marginal product of labor" MPL is the derivative of the output Q wrt units of 
labor L,  MPL = ∂Q/∂L.

Suppose the "production function" is taken as:
          Q = 36 K*L - 2 K^2 - 3 L^2
Calculate the values of MPK and MPL as functions of K and L.

Q : 36*K*L - 2*K^2 - 3*L^2;
MPK : diff (Q, K);
MPL : diff (Q, L);

## Income Determination Multipliers and Comparative 
    Statics  [6.2]

The partial derivative can be used to derive the various "multipliers" of an income  
determination model.
 
See Dowling, Ch. 2, Sec. 3,  and our wxMaxima worksheet Dowling02.wxmx, and  
Dowling02fit.pdf for an initial discussion of Income Determination Multipliers.

In calculating how the equilibrium level of an endogenous variable can be expected to 
change in response to a change in any of the exogenous variables or parameters, income  
determination multipliers provide an elementary exercise in what is called comparative 
static analysis or, more simply, comparative statics, which we will study later in greater
detail in Chapter 13.  

In an "open economy" in which trade with foreign nations occurs, demand for 
domestically produced goods and services (DD) is given by

       DD = C + I + G + (X - Z),

in which C is personal consumption of domestic goods and services, I is investment 
(from savings) in the means for future production (such as purchase of upgraded 
technology) , G is government expenditure on domestic goods and services, X is exports 
(that part of the demand for domestic goods that comes from abroad), and Z is (the 
domestic value of) imports - that part of domestic demand that is met by foreign supplied 
goods instead of domestically produced goods.

Typical contributors to exports X are wheat, computers, and U.S. vacations, all of which 
increase domestic production of goods and services.

Typical contributors to imports Z are French champagne, Korean cars and TV screens,
and Chinese solar panels, which replace domestic production of goods and services. The 
greater the domestic value of imports Z, the smaller the level of demand for 
domestically produced goods and services DD.

The quantity NX = (X - Z) is called the "net export" value. NX > 0 if we have a positive 
trade balance in which exports > imports. NX < 0 if we have a negative trade balance in 
which imports > exports.

We let Y stand for the value of domestic production of goods and services (GDP), 
also called "national income", "output", "production", and "domestic market".
GDP stands for "gross domestic product". The domestic goods market is in equilibrium 
when domestic production equals the demand for domestic goods and services DD.

      Y = DD = C + I + G + (X - Z)
 
We can determine the equilibrium level of national income Y if we assume a model in 
which consumption and investment each are partially a function of Y, but government
spending, exports, and imports are independent of Y:

         C = Co + b Y,     I = Io + a Y,    G = Go,    X = Xo,    Z = Zo,

where Co, Io, Go, Xo, Zo are given constants (independent of Y). 

In this model, b is the "marginal propensity to consume": b  = ∂C/∂Y, and a is the 
"marginal propensity to invest": a = ∂I/∂Y.

The Demand D  = C + I + G + X - Z = D0 + (b + a)*Y, where D0 is the autonomous
demand (independent of income Y), D0 = C0 + I0 + G0 + X0 + Z0. Equilibrium in the
goods market is determined by the condition that production equals demand, but
production has the same value as income, so the equilibrium equation is
  Y = D, or Y = D0 + (b + a)*Y.

wxdraw2d(xlabel = "Income Y", ylabel = "Demand D, Production Y",
    key_pos = top_left,
    title = "Demand slope = a + b = 0.4",
    proportional_axes = 'xy, key = "Production Y", explicit (x, x, 0, 10), color = red,
   key = "Demand D",    explicit (3 + 0.4*x, x, 0, 10), color = black, line_width = 1,
    key = "Ye = 5", explicit (5, x, 0, 5), key = "", parametric (5, yy, yy, 0, 5))$

We solve algebraically for the equilibrium value Ye in a purely symbolic problem first.
Instead of just writing down the solution, we show how steps can be arranged in Maxima
to have Maxima do the work, which might be useful in a more complicated problem.

C : Co + b*Y;
I : Io + a*Y;
G : Go;
X : Xo;
Z : Zo;
soln : solve (Y = C + I + G + (X - Z), Y);

Let Ye be the equilibrium value of Y,

Ye : rhs (soln[1]);

You can also use the alternative method:

Ye : at (Y, soln);

Let's multiply top and bottom by (-1):

Ye : (- num(Ye)) / (- denom (Ye));

Ye = (Co + Go + Io + (Xo - Zo) )/ (1 - b - a) is the equilibrium national income for this
model. Dowling uses an overbar instead of our lowercase e to signify this quantity.
The wxMaxima notebook has yet to provide an overbar for symbols, so we must adapt.

The partial derivative of Ye wrt any of the exogenous variables or parameters produces the
"multiplier" for that variable or parameter. For example ∂Ye/∂Go produces the
"government expenditure multiplier":

diff (Ye, Go);

If you look at the terms contributing to Ye, government expenditures G0 don't just
contribute the amount G0, but the (normally) increased amount G0/(1 - b - a), which is
why we call the factor 1/(1 - b - a)  a "multiplier". 

Likewise the import multiplier is ∂Ye/∂Zo, normally a negative number, given here by

diff (Ye, Zo);

The "marginal propensity to invest" is the parameter a. The multiplier for the CHANGE 
in the marginal propensity to invest is ∂Ye/∂a.

The small increase in Ye  (ΔYe) due to a small increase in the propensity to invest (Δa) is
given by ΔYe = ∂Ye/∂a * Δa.  Let daYe stand for the partial derivative ∂Ye/∂a here.

daYe : diff (Ye, a);

We can show that daYe is the same as Ye/(1-b-a):

is (equal (daYe, Ye/(1 - b - a)));

so ∂Ye/∂a = Ye/ (1 - b - a),  and  ΔYe = ∂Ye/∂a * Δa =  [Ye/ (1 - b - a)]*Δa, or

         ΔYe/Ye = [1/(1 - b - a) ]*Δa.

### Problem 6.5: Taxation, Saving, Balanced Budget Multiplier

Consider a closed economy model which includes a level of taxation T which indirectly 
affects the amount of personal consumption of goods and services C; that is we
assume C = C0 + b*(Y - T). The "disposable income" Yd  is income minus taxes,
Yd = Y - T. Because we consider a "closed economy", we ignore exports and imports.

           Y = C + I0 + G0,  C = C0 + b Yd,  Yd = Y - T,  T = T0.  

The level of taxation T = T0 is here "autonomous": it does not depend on national income Y.

### "Propensity to Save" Digression

A digression on saving following Blanchard's Macroeconomics, Sec. 3.4:

"Saving" is the sum of private saving and public saving.

By definition, "public saving" is defined as taxes minus government spending (T - G). If
taxes exceed government spending, the government is running a "budget surplus", so
public saving is positive. If taxes are less than government spending, the government is
running a "budget deficit", so public saving is negative.

By definition, "private saving" S is defined as disposable income Yd minus consumption:
     S = Yd  - C.
Since disposable income is income minus taxes, we then have 
     S = Y - T - C.

If we start with the equilibrium equation
   Y = C + I + G
and move consumption C to the left hand side, and then subtract taxes T from both sides,
we get
   Y - T - C = I + G - T.
On the left side we have private saving S, so S = I + G - T. Rearranging, we get
    I = S + (T - G), 
which says investment equals the sum of private saving S and public saving (T - G).

Equilibrium in the goods market requires that investment equals saving (private plus public).
What firms want to invest (in the means for future production) must be equal to what
people and the government want to save. Equilibrium in the goods market can now be
summarized in the two statements:

     Production = Demand
     Investment = Saving.

If C = C0 + b*Yd = C0 + b*(Y - T), private saving becomes S = Y - T - C0 - b*(Y - T),  or
      S = - C0 + (1 - b)*(Y - T)  =  - C0 + (1 - b)*Yd.
We can call (1 - b) the "marginal propensity to save" -- how much of an additional unit of
disposable income people save. With b between zero and one, (1-b) is also between zero
and one. Private saving increases with disposable income, but by less than one dollar
for each additional dollar of disposable income.

Returning to Prob. 6.5:
Calculate the effect on the equilibrium level of income Ye due to a 1 unit increase in 
government expenditure G0 exactly matched ("offset") by a 1 unit increase in  taxation T0.
That is, do the "comparative-static analysis" of finding the "balanced-budget multiplier" 
for an economy in which there is only autonomous taxation T0. 
Assume 0 < b < 1, so (1 - b) > 0.

T : T0;
Yd : Y - T;
C : C0 + b*Yd;
soln : solve (Y = C + I0 + G0, Y);

Let Ye be the equilibrium national income.

Ye : at (Y, soln);

Multiply both the numerator and denominator of Ye by (-1).

Ye : (- num (Ye)) / (- denom (Ye));

The small increase ΔYe in the equilibrium level of income Ye due to a small increase ΔG0 in 
government expenditure plus a small increase ΔT0 in taxation is approximately given by

        ΔYe = (∂Ye/∂G0) ΔG0 + (∂Ye/∂T0) ΔT0, 

which becomes (provided ΔG0 = 1 and ΔT0 = 1)
        ΔYe = ∂Ye/∂G0  + ∂Ye/∂T0 = mG0 + mT0,

letting mG0 stand for the multiplier ∂Ye/∂G0 and mT0 stand for the multiplier ∂Ye/∂T0.

mG0 : diff (Ye, G0);

mG0 = ∂Ye/∂G0 > 0 since 1 > b > 0, so (1 - b) > 0.

mT0 : diff (Ye, T0);

 Because 0 < b < 1,   mT0 = ∂Ye/∂T0 < 0.

Then with ΔG0 = 1 and ΔT0 = 1, the small increase ΔYe is (approximately)

dYe : mG0 + mT0, ratsimp;

An increase in government expenditure G0 matched by an equal increase in government 
taxation T0 (a balanced budget) will have a positive effect on the equilibrium level of 
income exactly equal to the increase in government expenditure and taxation. The
 "multiplier" in this case is +1, which is no multiplication at all, in this autonomous taxation
 model in which the amount of taxation is independent of the national income Y.

A "multiplier" refers to an economic factor that, when applied, amplifies the effect of some 
other outcome. A multiplier value of 2 would therefore have the result of doubling (2x) some 
effect; 3 would triple it (3x). In this example the "multiplier" is equal to 1, so there is no
amplification effect at work. If you increase taxes by the same amount as you increase 
government spending, the result is an increase in the equilibrium national income Ye by
the same amount as the increase in government spending.

You don't need the concept of multipliers to analyse this scenario. All you need is to assume
that ΔT0 = ΔG0 (and ΔC0 = 0 and ΔI0 = 0) to get

   ΔYe = (-b*ΔT0 + ΔG0)/(1 - b) = (- b +1)/(1 - b)*ΔG0 = ΔG0.

### Problem 6.6:  Modelling Taxes Rising with Income

Given the updated closed economy model

   Y = C + I0 + G0,    C = C0 + b Yd,     Yd = Y - T,   T = T0 + t Y,  
      with   0  <  b < 1 and 0 <  t  <  1,

where taxation T is now a function of income, demonstrate the effect on the equilibrium 
level of income Ye of a 1 unit increase in government expenditure G0 matched ("offset") 
by a 1 unit increase in autonomous taxation T0 . That is, demonstrate the effect of the 
balanced-budget multiplier in an economy in which taxes are a "positive function of 
income" (increase with income,  t > 0). 

T : T0 + t*Y;
Yd : Y - T;
C : C0 + b*Yd;
soln : solve (Y = C + I0 + G0, Y);

Ye : at (Y, soln);

Absorb the overall minus sign into the numerator with the following trick:

Ye : num(Ye) / denom (Ye);

If we again assume G0 and C0 are fixed and ΔT0 = ΔG0, we get
    ΔYe = (- b + 1)/[1 - b*(1 - t)]*ΔG0  <  ΔG0,
since (1 - b + b*t) > (1 - b). So ΔYe > 0  but less than ΔG0 in this scenario where taxation
is a positive function of national income, with 0 < t < 1.

As a specific numerical example, we use the parameters used by Dowell in Prob. 6.9.
We call this case66 since this is problem 6.6.

case66 : [C0 = 100, G0 = 330, I0 = 90, T0 = 240, b = 0.75, t = 0.2];
Ye66 : at (Ye, case66);

So the equilibrium national income (GDP) with this model and these numbers is
Ye = 850.

The government's "financial position" (either budget surplus, deficit, or balanced budget)
 is equal to the amount of receipts ( taxes T) minus government expenditures (G0).

govNet66 : at (T - G0, case66);

govNet66 : at (govNet66, Y = Ye66);

The government has a budget surplus equal to 80 for this case.

The small increase ΔYe in the equilibrium level of income Ye due to a small increase ΔG0 in 
government expenditure plus a small increase ΔT0 in autonomous taxation is given by
(approximately)
        ΔYe = (∂Ye/∂G0) ΔG0 + (∂Ye/∂T0) ΔT0, 

which becomes (with ΔG0 = 1 and ΔT0 = 1 )
        ΔYe = ∂Ye/∂G0  + ∂Ye/∂T0.

Let mG0 stand for the multiplier ∂Ye/∂G0 and mT0 stand for the multiplier ∂Ye/∂T0

mG0 : diff (Ye, G0);

The denominator is positive since (1 - b + b t) > (1 - b) > 0.

mT0 : diff (Ye, T0);

mT0 = ∂Ye/∂T0 < 0  since  b > 0 and the denominator > 0.

With ΔG0 = ΔT0 = 1, the small increase in Ye is:

dYe : mG0 + mT0, ratsimp;

We again absorb the overall minus sign into the numerator:

dYe : num(dYe)/ denom(dYe);

which is positive (dYe > 0) based on our assumptions about b and t. The denominator 
is positive since (1 - b + b t) > (1 - b) > 0. So dYe > 0 but dYe < 1 since the positive 
denominator is greater than the positive numerator.

An increase in government expenditures G0 with the same size increase in autonomous
taxes T0 in a model in which taxes T are positively related to income Y, will have a 
positive effect on the equilibrium level of income Ye, but the effect is smaller than we 
found in Prob. 6.5.

Here the multiplier is less than 1 because the total change in taxes
       ΔT = ΔT0 + t ΔY
is greater than the change in G0.

For our set of parameters (case66), we evaluate ΔYe induced by the combined unit 
increases ΔG0 =  ΔT0 = 1,

mG066 : at (mG0, case66);
mT066 : at (mT0, case66);

mG066 + mT066;

at (dYe, case66);

We have used the approximate differential ΔYe = (∂Ye/∂G0) ΔG0 + (∂Ye/∂T0) ΔT0
formula for the combined small increases in G0 and T0. We use this again to consider an 
increase in G0 (only) by the much larger amount ΔG0 = 50. The approximate change in 
Ye in this case (with  ΔT0 = 0) is

mG066*50;

Increased government spending leads to an increased national income Ye, (increase in 
GDP, domestic production).

We  next consider an increase in T0 (only) by the same large amount ΔT0 = 50. The 
approximate change in Ye in this case ( with  ΔG0 = 0 ) is

mT066*50;

Increased autonomous taxation leads to a decreased national income Ye.

### Increase Government Spending Option

Suppose "full employment Ye" is 1000, as compared with the value of 850 we have with 
the parameters in case66. To get a needed increase of Ye of the amount ΔYe = 150, we
again use our multipliers to consider first getting the increase by only increasing 
government spending. We let dG0 stand for the needed increase in G0 (alone),

solve ( 150 = mG066*dG0 );

An increased government expenditure of amount 60 will lead to an approximate increase 
of Ye by 150 and the new value of G0 is about 390. Call this increased G0 case case66g.

case66g :  ratsubst (G0 = 390, G0 = 330, case66);

Ye66g : at (Ye, case66g);

Because total tax receipts T increase with income, there will be an increase in total tax 
T as Ye increases to 1000 (keeping T0 constant).

T;

T66g : at (T, case66g);

T66g : at (T66g, Y = Ye66g);

With T = 440 and G0 = 390 the budget surplus is 440 - 390 = 50, a smaller budget surplus
compared with the previous budget surplus of 80.

If instead we consider a change in the value of T0 (instead of an increase in government 
autonomous expenditures G0), we use the multiplier mT066. Let the needed change be 
dT0.

solve (150 = mT066*dT0);

### Decrease Autonomous Taxation Option

The government can instead decrease autonomous taxes by 80 to increase Ye by 150.
Call this case66t, with T0 = 240 - 80 = 160.

case66t : ratsubst (T0 = 160, T0 = 240, case66);

Ye66t : at (Ye, case66t);

T66t : at (T, case66t);

T66t : at (T66t, Y = Ye66t);

With T0 reduced to 160 and G0 = 330, Ye = 1000, T = 360 and the budget surplus is 
now 360 - 330 = 30. A larger budget surplus (50) is achieved with an increase in 
autonomous government spending (G0) compared with a decrease in autonomous
taxation (T0), given the goal of getting Ye to "full employment" value.

### Problem 6.7  Include Imports Rising with Income

In an open economy, (X = exports, Z = imports),  consider the model

          Y = C + I0 + G0 + X0 - Z,    C = C0 + b Yd,     Yd = Y - T,   T = T0 + t Y,
                and Z = Z0 + z Yd,

and determine the effect on the equilibrium level of income Ye of a 1 unit increase in 
(a) exports X0, (b) autonomous imports Z0, and (c) autonomous taxation T0. 

In short, perform the comparative-static analysis of finding the export, autonomous import, 
and autonomous taxation multipliers. Assume all the independent variables are positive
and 0 <  b, t, z < 1.

Note that because the "disposable income" Yd = Y - T, so C = C0 + b Y - b T, the 
marginal propensity to consume ∂C/∂Y = b. Likewise, Z = Z0 + z Yd = Z0 + z Y - z T, and 
the marginal propensity to import is ∂Z/∂Y = z. We assume below that b > z.

T : T0 + t*Y;
Yd : Y - T;
Z : Z0 + z*Yd;
C : C0 + b*Yd;
solns : solve (Y = C + I0 + G0 + X0 - Z, Y);

Equilibrium national income Ye:

Ye : at (Y, solns);

Multiply the top and bottom of this fraction by (-1):

Ye : (- num (Ye)) / (- denom (Ye));

The denominator of Ye can be written as  D = 1 + (z-b)*(1-t), or in the alternative 
form Da = (1-b) + b*t + z*(1-t), in which each term of Da is positive, so D > 0.

D : 1 + (z - b)*(1 - t);
is (equal (denom(Ye), D));

Da : (1-b) + b*t + z*(1-t);
is (equal ( denom (Ye), Da));

Let DD be a placeholder for D, as the denominator of Ye, and define Yed as the numerator
of Ye divided by DD. 

Yed : num(Ye)/DD;

General balance of payments BP = exports minus imports =  X - Z = X0 - Z for arbitrary 
values of Y is:

BP : X0 - Z, expand;

The export multiplier mX0 = ∂Ye/∂X0.  Use the Yed expression for now.

mX0 : diff (Yed, X0);

The autonomous import multiplier mZ0 = ∂Ye/∂Z0:

mZ0 : diff (Yed, Z0);

The autonomous taxation multiplier mT0 = ∂Ye/∂T0:

mT0 : diff (Yed, T0);

DD stands for D, but DD is not "bound" to anything, so it remains just DD.

Hence mX0 = 1/D > 0, mZ0 = - 1/D = - mX0 < 0, and mT0 = - (b - z)/D < 0
since we assume b > z (the marginal propensity to consume b is greator than
the marginal propensity to import z).

With z > 0, the decrease in Ye due to an increase in autonomous taxes T0 is reduced by 
the presence of z in the numerator of mT0. Increased taxes will reduce the cash outflows 
for imports and thus reduce the negative effect of increased taxes on Ye.

The autonomous government expenditure multiplier mG0 = ∂Ye/∂G0 is

mG0 : diff (Yed, G0);

As a numerical example of this model we define case67 using the parameters
in Dowling's Prob. 6.13.

case67 : [C0 = 125, G0 = 600, I0 = 92.5, T0 = 150, X0 = 150, Z0 = 55, b = 0.9,
     t = 0.2, z = 0.15];
Ye67 : at (Ye, case67);

Budget deficit = 50 = receipts (taxes) - expenditures = T - G0.

govNet67 : at (T - G0, case67);

govNet67 : at (govNet67, Y = Ye67);

Balance of payments BP = -122.5 = exports (X0) - imports (Z)

BP67 : at (BP, case67);

BP67 : at ( BP67, Y = Ye67);

### Increase Government Spending Option

Suppose full employment Ye value is 2075, which requires an increase in Ye of 
amount 75. What increase in government expenditure G0 (only) will be required and what 
are the budget and balance of payments implications?

ΔYe = 75  = ∂Ye/∂G0 ΔG0 = mG0*ΔG0. Let dG0 be the needed increase in G0.

mG0 : at (mG0, DD = D);

mG067 : at (mG0, case67);

solve (75 = 2.5*dG0);

So we need to increase government spending by 30.  Let's call this case67g, with 
G0 increased to G0 = 600 + 30 = 630. We edit the list case67 to define case67g.

case67g : ratsubst (G0 = 630, G0 = 600, case67);

Ye;

Ye67g : at (Ye, case67g);

The new budget deficit = 65  = receipts (taxes) - expenditures, has increased from 50, 
so the budget deficit cost of this scenario is 15.

govNet67g : at (T - G0, case67g);

govNet67g : at (govNet67g, Y = Ye67g);

The new balance of payments BP = -131.5 = exports - imports = (X0 - Z), "net exports", 
 and the magnitude of trade imbalance has increased from 122.5 to 131.5.

BP67g : at (BP, case67g);

BP67g : at (BP67g, Y = Ye67g);

BP67g : at ( at (BP, case67g), Y = Ye67g);

### Decrease Autonomous Taxation Option

Suppose the "full employment Ye value" is 2075, which requires an increase in Ye of 
amount 75. What change in taxes T0 (only) would be required to achieve this and what 
are the budget deficit and balance of payments implications?

ΔYe = 75  = ∂Ye/∂T0 ΔT0 = mT0 ΔT0, so solve this for the required increase in T0.
We have defined the quantity mT0 symbolically above; call the needed increase
dT0. This calculation is based on our original numbers for case67. We need to replace the
"placeholder" DD with D.

mT067 :   at ( at (mT0, DD = D), case67);

eqn : 75 = mT067*dT0;

solve (eqn);

We can achieve the full employment equilibrium value Ye = 2075 by cutting taxes by 40
from its original value of 150, ie., cut taxes to 110 from 150. Call this case67t, and edit 
the case67 list of numbers to create case67t.

case67t : ratsubst (T0 = 110, T0 = 150, case67);

Ye67t : at (Ye, case67t);

The new value of  [receipts (taxes) - expenditures] is -75 instead of the original value 
of -50, so the budget deficit cost of this scenario is 25.

govNet67t : at (T - G0, case67t);

govNet67t : at (govNet67t, Y = Ye67t);

The new balance of payments BP = -137.5 uvt = exports - imports = (X0 - Z), "net exports", 
 and the magnitude of trade imbalance has increased from 122.5 to 137.5 uvt.

BP67t : at (BP, case67t);

BP67t  : at (%, Y = Ye67t);

### Decrease Marginal Propensity to Import Option

Returning to the original Prob. 6.7 scenario and numbers given by case67, calculate the 
change in the equilibrium GDP value Ye induced by a one percent DECREASE in the 
marginal propensity to import z. 

Let mz = ∂Ye/∂z. Then ΔYe = mz * Δz, and we are instructed to use Δz = - 0.01*z. 
Let dYe stand for the change ΔYe. We first calculate the multiplier mz for a general case.

mz : diff (Ye, z), ratsimp;

grind(%)$

and then for case67:

mz67 : at (mz, case67);

dz : at (-0.01*z, case67);

dYe : mz67*dz;

Hence a one percent decrease in the marginal propensity to import z (which thus
results in less imports) would yield an increase of about 5.48 in GDP Ye.

## Income and Cross Price Elasticities of Demand [6.3]

### Elasticities in General

If y = f(x) is any differentiable function, the elasticity of y with respect to x is defined as
     ε_{y, x} = (x/y) * dy/dx
which can be rewritten as (if dy -> Δy and dx --> Δx)
   ε_{y, x} = (dy/y)/(dx/x)  = (fractional change in y) / (fractional change in x),
which is a pure number without units, and a number which is independent of the units
used for x and for y.  

Because percentage change = fractional change*100%, the elasticity of y with respect to
x is the ratio of the percentage change in the dependent variable y divided by the 
percentage change of the independent variable x.

The fractional change in a variable (either dependent or independent) is equal to the
differential of the natural logarithm of the variable. Suppose u = ln(x).  Then
     du/dx = d(ln(x))/dx = 1/x.
Multiplying both sides by dx, we get, as a general result:
     dx/x = d(ln(x)),  so we also have dy/y = d(ln(y)), etc.

Recall the general relations which involve the natural logarithm:
   ln(A*B) = ln(A) + ln(B),  ln(A^a) = a*ln(A).

Economists often use equations which are "linear in logarithms". For example, suppose
y = 7*x^3. Taking the natural logarithm of each side, we must also have the relation
ln(y) = ln (7*x^3) = ln(7) + ln(x^3) = ln(7) + 3*ln(x). We see ln(y) is linear in ln(x).
Taking the differential of both sides, and using d(ln(constant)) = 0, we get: 
  d(ln(y)) = 3*d(ln(x)),  or   dy/y = 3*[dx/x], and the elasticity of y with respect to x is 3.
     

### Demand Elasticities

Dowling uses the symbol ε_Y for the elasticity of demand with respect to income Y
("income elasticity of demand"), given the demand function Q1(P1, P2, Y), in which 
Q1 is the number of units per unit time period of good x1 as a function of the price 
per unit of good x1, P1, the price per unit of some competing good x2, P2, and 
the income per unit time Y.

For convenience in using Maxima, we will use the symbol Ey for ε_Y. Hence
   Ey = [dQ1/Q1] / [dY/Y] = (Y/Q1)*(dQ1/dY).

Dowling uses the symbol ε_c for the elasticity of demand with respect to price per unit
of good x2, P2, ("cross price elasticity of demand"). For convenience we will use Ec
for this elasticity. Hence
    Ec = [dQ1/Q1] / [dP2/P2] = (P2/Q1)*(dQ1/dP2).

"Cross price elasticity of demand" Ec measures the relative responsiveness of the
demand for one product to changes in the price of another product, when all other 
variables are held constant. 

Suppose the demand function Q1(P1,P2,Y) is given by the linear function
 (a, b, c, m are given exogenous parameters):

                 Q1 =  a - b P1 + c P2 + m Y.

Then Ey = (Y/Q1)*m, and the sign of Ey is the same as the sign of the parameter m.
(Q1, P1, P2, and Y are all assumed positive.)

If 0 < Ey < 1, (positive but less than one) it can be expected that demand for the good x1
will increase with national income, but  the increase will be less than proportionate. 
Thus, while demand grows absolutely, the relative market  share of the good will decline 
in an expanding economy (Y increasing).

If Ey > 1, (greater than one) the demand for the product will grow faster than the 
rate of expansion of the economy, and increase its relative market share as Y increases.

If  Ey < 0, (is a negative number) demand for the good would decline as income Y increases. 

Ec = (P2/Q1)*c, and the sign of Ec is the same as the sign of the parameter c.

### Examples 1 & 2 Substitute Goods, Complementary Goods

Let Qb(Pb, Pp, Y) be the number of units of beef demanded per unit time, as a function 
of Pb, the price per unit of beef, Pp, the price per unit of pork, and the income per
unit time Y.

Assume the demand for beef is given by the linear function:
    Qb  = 4850 - 5 Pb + 1.5 Pp + 0.1 Y.
Also assume that at a given time Y = $10,000 (per unit time period),  Pb = $200/unit,
 and Pp = $100/unit.

Find the income elasticity of demand for beef Ey and the cross price elasticity 
of demand for beef Ec

The needed first partial derivatives are, by inspection, ∂Qb/∂Y = 0.1, 
∂Qb/∂Pp = 1.5. To calculate the needed elasticities we also need the numerical
quantity of Qb and we calculate that number as the last element of this list:

Pb : 200;
Pp : 100;
Y : 1e4;
Qb : 4850 - 5*Pb + 1.5*Pp + 0.1*Y;

The income elasticity of demand for beef is then, using ∂Qb/∂Y = 0.1,

Ey : 0.1*(Y/Qb);

We have emphasized that by virtue of its definition, Ey is dimensionless.

With Ey = 0.2  < 1, beef is "income-inelastic" and 

    (% increase in demand for beef ) = (2/10) * (% increase in income).

For any given percentage increase in national income (GDP), demand for beef will 
increase less than proportionately. Hence the relative market share of beef will decline 
as the economy expands (Y gets larger). Since the income elasticity of demand suggests 
the "growth potential" of a market, the growth potential of beef in this scenario (model) 
is limited. 

The cross price elasticity of demand for beef is, using ∂Qb/∂Pp = 1.5, 

Ec : 1.5*(Pp/Qb);

Then the (fractional increase in units of beef demanded) = 0.03*(fractional increase in
price per unit of pork)
        (ΔQb/Qb) = 0.03*(ΔPb/Pb).

Suppose the price of pork increases by 10%. That means that  ΔPp/Pp = 0.1, and then
ΔQb/Qb = 0.003 = 0.3%.

As the price of pork increases, shoppers buy less pork and more beef, since either
one can be used as an entree.

For "substitute goods," such as beef and pork, ∂Q1/∂P2 > 0 (in our example, 
∂Qb/∂Pp = 1.5 is positive) and the cross price elasticity Ec is positive. 

"Substitute goods" refer to those goods that can be consumed in place of each other,
such as (beef and pork) or (tea and coffee).

Quoting Wikipedia:
"In microeconomics, two goods are "substitutes" if the products could be used for the 
same purpose by the consumers. That is, a consumer perceives both goods as similar 
or comparable, so that having more of one good causes the consumer to desire less 
of the other good."
------------------------------------------------------------------------------------------
For "complementary goods," ∂Q1/∂P2 < 0 and the cross price elasticity Ec will be 
a negative number. 

"Complementary goods" refer to those goods that are consumed together, such as
(rice and beans) or (tea and sugar) or (fish and chips).

Quoting Wikipedia: "In economics, a complementary good is a good whose appeal 
increases with the popularity of its complement. Technically, it displays a negative 
cross elasticity of demand; and that demand for it increases when the price of 
another good decreases."
-------------------------------------------------------------------------------------------
If  ∂Q1/∂P2 = 0, the goods are "unrelated" and Ec = 0.
--------------------------------------------------------------------------------------------

Substitute goods (or simply "substitutes") are products which all satisfy a common want 
and complementary goods (or simply "complements") are products which are consumed 
together. Demand for a product's substitutes increases and demand for its complements 
decreases if the product's price increases.

Always consider the cost of substitution – there might be "switching costs" for consumers 
if they opt for a new brand. Some products are close substitutes with a high (positive) 
cross price elasticity of demand. Others are weaker substitutes especially when 
consumer/brand loyalty is high.

See the web article "Substitute goods and reasoning from a price change"
by Scott Sumner at 
    https://www.econlib.org/archives/2015/04/substitute_good.html
for a cautionary post about supply and demand arguments about price changes in
elementary economics courses.

### Problem 6.21 Cross Price Elasticity, Three Goods

The demand function for good 1 is
     Q1  = a + b P1 + c P2 + d P3 + f Y
Let E12 be the cross price elasticity relating the price of good 2 and the value of Q1, 
and let E13 be the cross price elasticity relating the price of good 3 with the value of Q1.

[P1, P2, Y];

[a,b,c,d,f];

kill (Y)$
Q1 : a + b*P1 + c*P2 + d*P3 + f*Y;
E12 : P2*diff (Q1, P2)/Q1;
E13 : P3*diff (Q1, P3)/ Q1;

Assume the numerical values (surpressing dimensions) are:
a = 50, b = -4, c = -3, d = 2, f = 0.001, P1 = 5, P2 = 7, P3 = 3, Y = 11,000.

Find the numerical values of E12 and E13 and the percent change of Q1 if
there is a 10% increase in P2 (only) or a 10% increase in P3 (only).

case621 : [a = 50, b = -4, c = -3, d = 2, f = 1e-3, P1 = 5, P2 = 7, P3 = 3, Y = 1.1e4];

grind(%)$

Let Q1n hold the numerical value of Q1 for this numerical case, etc.

Q1n : at (Q1, case621);

E12n : at (E12, case621);

E13n : at (E13, case621);

The percent increase in Q1 due to a 10% increase in P2 is (note that percent is unbound)

E12n*10*percent;

Goods 1 and 2 are "complements" (for example rice and beans); an increase in the price 
of good 2 results in a decrease in Q1.

The percent increase in Q1 due to a 10% increase in P3 is (note that percent is unbound)

E13n*10*percent;

Goods 1 and 3 are substitutes (for example beef and pork); an increase in P3 results in 
an increase in Q1.

## Optimizing Economic Functions  [6.5]

Food processors frequently sell different grades of the same product: quality, standard, 
economy;  some, too, sell part of their output under their own brand name and part under 
the brand name of a large chain store. Clothing manufacturers and designers frequently 
have a top brand and cheaper imitations for discount department stores. Maximizing profits 
or minimizing costs under these conditions involve functions of more than one variable. 
Thus, the basic rules for optimization of multivariate functions (see  Section 5.4) are required. 
See Examples 5 and 6 and Problems 6.22 to 6.27. 

### Conditions for a Relative Maximum or Minimum

(Review of material covered in Dowling05.wxmx.)

Given a function F(x, y), we must first be considering a critical point (x0, y0) at which 
both Fx = ∂F/∂x = 0 and Fy = ∂F/∂y = 0. 

With Fxx = ∂²F/∂x², Fyy = ∂²F/∂y²,  and Fxy = (Fx)y = ∂(Fx)/∂y = ∂²^F/(∂x∂y),

we  have a RELATIVE MINIMUM  provided
    Fxx > 0 and Fyy > 0  (convex) and
    Fxx*Fyy  >  (Fxy)^2   (not a saddle point or an inflection point)
at the considered critical point,

we  have a RELATIVE MAXIMUM  provided
    Fxx < 0 and Fyy < 0  (concave) and
    Fxx*Fyy  >  (Fxy)^2   (not a saddle point or an inflection point)
at the considered critical point.

Suppose that (a,b) is a critical point of F(x,y) and that the second order 
partial derivatives are continuous in some region that contains (a,b). 

Next define, 
    D = D(a,b) = Fxx (a,b) Fyy (a,b) - [Fxy (a,b)]^2

We then have the following classifications of the critical point.

1. If D > 0  and Fxx(a,b) > 0  then there is a relative minimum at  (a,b). 
    In this case both Fxx and Fyy are positive (convex).
2. If D > 0  and Fxx(a,b) < 0  then there is a relative maximum at (a,b),
    In this case both Fxx and Fyy are negative (concave).
3. If D < 0 then the point (a,b) is a saddle point (convex in one direction, 
      concave in the orthogonal direction) if Fxx and Fyy have opposite
      signs at the critical point, and is an inflection point if Fxx and Fyy
       have the same signs at the critical point.
4. If D = 0 then the point (a,b) may be a relative minimum, relative maximum 
     or a saddle point. Other techniques would need to be used to classify 
     the critical point.

### Example 5,   Analyze (expr, critPts) , plotCP (expr, critPt)

A firm producing two goods x and y has the profit function π(x,y):
     π  = 64 x - 2 x^2 + 4 x y - 4 y^2 + 32 y - 14.
Find the profit maximizing level of output for x and for y, and check that the critical values
imply maximization. Maxima will not allow a numerical assignment to the symbol π, so
we use Pr in Maxima to stand for the profit π.

Analyze (expr, critPts) is a critical point analysis function which uses Maxima's hessian 
matrix and determinant functions to perform the required check of the second derivatives
at the critical point.
 
Analyze prints out information about the nature of the critical point(s) and also the values
of the second derivatives of expr at the critical point(s).
For example [diff (expr,x,2), diff (expr,y,2), diff(expr,x,1,y,1)] evaluated at the critical point(s).

This function is defined in Econ1.mac.

SYNTAX:

             Analyze (expr, critPts) 
expr depends on two variables, which do not have to be x and y.  critPts is either one 
critical point or a list of several critical points of the two variable expression expr.

 acceptable forms for critPts (assuming expr depends on x and y):

 [x = 3, y = 7], 
  or [[x = 3, y = 7]]
  or [[x = 3, y = 7], [x = -3, y = 7]]
  or [[x = 3, y = 7], [x = -3, y = 7], [x = 0, y = 0]], etc.

In our Example 5,  π(x,y) --> Pr(x,y) is defined as a Maxima expression. 

Let gradPr be a list of the first derivatives of the Maxima expression Pr, to be 
passed to Maxima's solve function.

Instead of defining gradPr  using
     gradPr :  [diff (Pr,x), diff (Pr,y)];
it is somewhat less work to use the Maxima function jacobian in the form 
     gradPr : jacobian ([Pr], [x,y] )[1];
as shown in this example.

[x,y];

Pr : 64*x - 2*x^2 + 4*x*y - 4*y^2 + 32*y - 14;
gradPr : jacobian ([Pr],[x, y])[1];
solns : solve (gradPr, [x,y]);

critPt : solns[1];

at (Pr, critPt);

Analyze (Pr, critPt);

The second derivative of Pr wrt x (evaluated at the critical point) is - 4, the 2nd derivative
of Pr wrt y is - 8, and the cross derivative ∂²Pr/∂x∂y = 4
(Pr)xx and (Pr)yy are both negative (concave in both directions) and 32 > 16 so not
a saddle point. Hence we have a true maximum.

A "do it yourself" check:

secondDeriv : [diff (Pr, x, 2), diff (Pr, y, 2), diff (Pr, x, 1, y, 1)];

In this example, the list of second derivatives is totally numerical, so there is no need here
for the normal second step of evaluating the 2nd derivatives at the critical point(s) found.

The maxima function hessian (which produces a matrix of second derivatives), used 
in the next cell, has (Pr)xx and (Pr)yy on the diagonal and (Pr)xy = (Pr)yx on 
the off-diagonal; this is a faster way to check the second derivatives, and is used in 
the Maxima function Extr (defined in Econ1.mac) called by Analyze.

hessian (Pr, [x, y]);

The Maxima function plotCP (expr, critPt) is defined in Econ1.mac.

plotCP (Pr, critPt);

If you right-click the image and choose "popout interactively", you get a separate Gnuplot
window. Expand that window to fullscreen, and drag the image by holding down the left 
mouse button. This let's you view the surface near the critical point from different angles.

You must close the separate Gnuplot window before you can continue with your 
calculations.

If it is more convenient to work with a Maxima function (instead of, or in addition to) a 
Maxima expression, you can use the following device, which amounts to placing two single 
quotes (') immediately in front of the expression symbol Pr.

g (x,y) := ''Pr;

g(40,24);

For example, we can make a 2d plot of g(x,24) which shows the shape of the maximum
in the plane y = 24.

wxdraw2d ( xlabel = "x", ylabel = "PROFIT", yrange = [1450, 1700], 
    explicit (g (x, 24), x, 30, 50), color = black, line_width = 1,
    parametric (40, yy, yy, 1450, 1650) )$

The same 2d plot in the plane y = 24 could be made without defining a Maxima function.
Use:   explicit (subst (24,y, Pr), x, 30, 50).

wxdraw2d ( xlabel = "x", ylabel = "PROFIT", yrange = [1450, 1700], 
    explicit (subst (24, y, Pr), x, 30, 50), color = black, line_width = 1,
    parametric (40, yy, yy, 1450, 1650) )$

### Example 6  Maximize Profit

In monopolistic competition producers must determine the price that will maximize their 
profit. Assume that a producer offers two different brands of a product, for which the 
demand functions are 
       Q1 = 14 - 0.25 P1,            Q2 = 24 - 0.5 P2,
and the "joint cost function" is TC = Q1^2 + 5 Q1*Q2 + Q2^2.
Construct a profit function π (revenue - cost) and use profit maximization to determine
the optimum output of brands 1 and 2 and the optimum prices of brands 1 and 2.

We express the profit function in terms of Q1 and Q2, and first solve for P1 and P2
(the "inverse demand functions") in terms of Q1 and Q2 respectively.

First solve for P1 and P2 (the "inverse demand functions") in terms of Q1 and Q2 
respectively.

[P1,P2];

[Q1,Q2];

kill (Q1, Q2)$
solns : solve ( [Q1 = 14 - 0.25*P1, Q2 = 24 - 0.5*P2], [P1, P2] );

Demand : solns[1];

Define general expressions for total revenue TR, and total cost TC:

TR : P1*Q1 + P2*Q2;
TC : Q1^2 + 5*Q1*Q2 + Q2^2;

Let Pr stand for the profit function π =  revenue minus cost, and replace P1 and P2 by 
their definitions as defined by the list Demand. This gives the profit Pr as a function 
of Q1 and Q2.

Pr : at (TR - TC, Demand), expand;

Find the critical points where the first derivatives of Pr wrt Q1 and Q2 are respectively
equal to zero.

gradPr : jacobian ([Pr], [Q1, Q2])[1];
solns : solve (gradPr, [Q1,Q2]), numer;

critPt : solns[1];

at (Pr, critPt);

hessian (Pr, [Q1, Q2]);

Analyze (Pr, critPt);

The second derivative of Pr wrt Q1 (at the given critical point) is -10, the second derivative
of Pr wrt Q2 is -6, and the cross derivative ∂²Pr/∂Q1∂Q2 = -5.
π11 and π22 are both negative (concave in both directions) and 60 > 25 so not
a saddle point. Hence we have a true maximum.

Values of the per unit prices of goods 1 and 2, P1 and P2, at the maximum profit point:

Prices : at (Demand, critPt);

plotCP (Pr, critPt);

## Constrained Optimization in Economics

Solutions to economic problems frequently have to be found under constraints (e.g., 
maximizing utility subject to a budget constraint or minimizing costs subject to some 
such minimal requirement of output as a production quota). Use of the Lagrangian 
function (see Section 5.5) greatly facilitates this task. See Example 7 and Problems 
6.28 to 6.39. For inequality constraints, see concave programming (Section 13.7) in 
Chapter 13. 

We introduced the use of a Lagrange multiplier for constrained optimization in a case
in which some expression was required to equal zero, using Maxima, in Dowling05.wxmx.
See also Dowling05fit.pdf.

### Example 7,  Minimize Costs with One Equality Constraint

### Lagrange Multiplier Method, optimum (expr, varL, constraints)

Find the critical values for minimizing the costs of a firm producing two goods x
and y when the total cost function is
     c = 8 x^2 - x y + 12 y^2
and the firm is bound by contract to produce a minimum combination of goods
totaling 42, that is, subject to the constraint x + y = 42, or 42 - g = 0, where g = x + y.

We will first use the Maxima function optimum (expr, varL, constraints), defined in 
Econ1.mac, which can be used for one or two equality constraints. expr depends on two
or more variables, which do not have to be called x and y.

We first use optimum (expr, varL, constraints). We used optimum in Ch. 5.

[c, g, x, y];

c : 8*x^2 - x*y + 12*y^2;
g : x + y;
optimum (c, [x, y], 42 - g);

optimum has found a relative minimum at x = 25, y = 17, where the cost is 8043.
optimum forms a Lagrangian function, here with one Lagrange multiplier lam[1], passes the
first derivatives to solve and looks at the leading principal minors of the bordered Hessian
matrix to analyze critical points found by solve. 

See Dowling Ch. 12 for a discussion of this method of investigating critical points in the 
presence of equality constraints.

"DO IT YOURSELF"

Form the Lagrangian function L = c + λ (42 - g), and look for the critical point(s) at which
simultaneously the derivatives wrt x,y,λ are each equal to zero.

First step: form the Lagrange function L with a Lagrange multiplier λ.

L : c + λ*(42 - g);

Find the first order partial derivatives of L wrt x, y, and λ, and require them all to be
equal to zero for there to be a critical point of the Lagrange function L.

gradL : jacobian ([L], [x, y, λ])[1];
solns : solve (gradL, [x, y, λ]);

soln : solns[1];

critPt : rest (soln, -1);

Evaluate the cost function (expression) at the critical point found.

at (c, critPt);

For more complicated cost functions and/or constraints, solve may not be able to find 
the critical point and one should use a numerical method such as mnewton, as we 
discussed in Dowling05.wxmx.

### Method of Substitution

An alternative to the Lagrange multiplier method is simply using the constraint to replace
one of the variables by the other to produce a cost function which only depends on one
variable. We can then look for a minimum in say f(x), use the value of x producing such
a minimum in f(x), call it xs, then use x = xs with the constraint to solve for ys, and we 
then know the critical point (xs,ys) and can find the minimum cost. We can then check 
for a true minimum by plotting the cost function as a function of x and the cost function 
as a function of y separately.

We implement that strategy here.

Let C1 be the cost as a function of good x after incorporating the constraint.

[ x, y];

c : 8*x^2 - x*y + 12*y^2;
C1 :  at (c, y = 42 - x), expand;

S1 : solve (diff (C1,x), x);

Critical point:

xs : at (x, S1);

ys : at (42 - x, S1);

Minimum cost using C1 and the critical point values:

C1s : at (C1, x = xs );

A 2d plot of the cost as a function of good x.

wxdraw2d ( xlabel = "x", ylabel = "C1(x)", explicit (C1, x, 20, 30) )$

Let C2 be the cost as a function of good y after incorporating the constraint.

C2 : at (C1, x = 42 - y), expand;

solve (diff (C2, y), y);

We get the same minimum cost from C2:

C2s : at (C2, y = 17);

The original cost function c, depending on both x and y, with no knowledge of
the constraint, also yields the same minimum cost:

at (c, [x = xs, y = ys]);

A 2d plot of the cost as a function of good y using C2.

wxdraw2d ( xlabel = "y", ylabel = "C2(y)", explicit (C2, y, 15, 20) )$

The disadvantages of the simpler substitution method are

1. It may not be easy to do the substitution if the constraint involves an implicit
function of the two variables, or involves complicated special functions.

2. We don't have available a Lagrange multiplier value (depending on the numerical
value of the constraint target), which value gives us an approximate value for the
increase in the mimimim cost induced by a one unit increase of the constraint
target (42 --> 43).

### Problem 6.32  Maximize Profit Subject to Constraint

A monopolistic firm has the following demand functions for each of its products,
x and y:
   x = 72 - 0.5 Px,     y = 120 - Py,

The combined cost function is c = x^2 + x y + y^2 + 35, and maximum joint production
is 40,  so   x + y =  40.  Find the profit maximizing level of a) output, b) price, and c)profit.

We first need to construct a profit function π (revenue - cost), and express the profit 
function in terms of x and y. We first solve for the per unit prices Px and Py (the "inverse 
demand functions") in terms of x and y respectively.

[x,y,Px,Py];

solns : solve ([x = 72 - 0.5*Px, y = 120 - Py], [Px, Py] );

demand :  solns[1];

Let Pr stand for the profit function π, with revenue = Px*x + Py*y, expressed in terms of
x and y, and cost = c.

c : x^2 + x*y + y^2 + 35;
g : x + y;
Pr : at (Px*x + Py*y - c, demand), expand;

We first use optimum (expr, varL, constraints) defined in Econ1.mac. For one or two
equality constraints, optimum uses the bordered Hessian matrix and the leading principal
minors test described in Dowling Ch. 12 and Dowling11-12.wxmx.

optimum (Pr, [x, y], 40 - g);

optimum has found a relative maximum at x = 18, y = 22, profit = 2861.
optimum produces a global list cp, which in this problem has only one critical point found by
solve.

cp;

cp1 : cp[1];

critPt : rest (cp1, -1);

Prices : at (demand, critPt);

"DO IT YOURSELF"

Let L be the Langrange function with λ being the Lagrange multiplier. To find the
critical points of L we need the first derivatives of L wrt x, y, and λ to all be simultan-
eously equal to zero.

L : Pr + λ*(40 - g);
gradL : jacobian ([L], [x, y, λ] )[1];
solns : solve (gradL, [x, y, λ]);

### The Concept of Economic Utility

Utility refers not to usefulness but to the flow of pleasure or happiness that a person 
enjoys – some measure of the satisfaction a person experiences.

From IEA, Sec. 12.1 (see References):

"Economists use the term utility in a peculiar and idiosyncratic way. 'Utility' refers 
not to usefulness but to the flow of pleasure or happiness that a person enjoys – 
some measure of the satisfaction a person experiences. Usefulness might 
contribute to utility, but so does style, fashion, or even whimsy."

"The term utility is unfortunate not just because it suggests usefulness, but 
because it makes the economic approach to behavior appear more limited than it 
actually is. We will make very few assumptions about the form of utility that a 
consumer might have. That is, we will attempt to avoid making value judgments 
about the preferences a consumer holds – whether they like smoking cigarettes 
or eating only carrots, watching Arnold Schwarzenegger movies, or spending time 
with a hula hoop. Consumers like whatever it is that they like; the economic 
assumption is that they attempt to obtain the goods that they like. It is the 
consequences of the pursuit of happiness that comprise the core of consumer 
theory." 

"In this chapter, we will focus on two goods. In many cases, the generalization to 
an arbitrary number of goods is straightforward. Moreover, in most applications 
it won’t matter because we can view one of the goods as a 'composite good' 
reflecting consumption of a bunch of other goods. [Thus, for example, savings
for future consumption, or to provide for descendents, or to give to your alma
mater, are all examples of consumption. Our consumer will, in the end, always 
spend all of her income, although this happens because we adopt a very broad 
notion of spending. In particular, savings are 'future spending'.]"

"As a starting point, suppose the two goods are X and Y. To distinguish the quantity 
of the good from the good itself, we’ll use capital letters to indicate the good and 
a lower case letter to indicate the quantity consumed. If X is rutabagas, a consumer 
who ate three of them would have x = 3. How can we represent preferences for this 
consumer? To fix ideas, suppose the consumer is both hungry and thirsty and the 
goods are beer and pizza. The consumer would like more of both, reflected in 
greater pleasure for greater consumption. Items one might consume are generally 
known as 'bundles', as in bundles of goods and services, and less frequently 
as 'tuples', a short-form for the 'n-tuple', meaning a list of n quantities. Since we 
will focus on two goods, both of these terms are strained in the application; 
a bundle because a bundle of two things isn’t much of a bundle, and a tuple 
because what we have here is a 'two-tuple', also known as a pair. But part of the 
job of studying economics is to learn the language of economics, and bundles it is." 

"One might naturally consider measuring utility on some kind of physical basis – 
production of dopamine in the brain, for example – but it turns out that the actual 
quantities of utility don’t matter for the theory we develop. What matters is 
whether a bundle produces more than another, or less, or the same. Let u(x,y) 
represent the utility a consumer gets from consuming x units of beer and y units 
of pizza. The function u guides the consumer’s choice, in the sense that, if the 
consumer can choose either (x1,y1) or (x2,y2), we expect him to choose (x1,y1)
if u(x1,y1) > u(x2,y2)."

"But notice a doubling of u would lead to the same choices, because 
   u(x1,y1) > u(x2,y2)  if and only if 2*u(x1,y1) > 2*u(x2,y2)."

"Thus, doubling the utility doesn’t change the preferences of the consumer. But the 
situation is more extreme than this. Even exponentiating the utility doesn’t change 
the consumer’s preferences, because
   u(x1,y1) > u(x2,y2)  if and only if e^u(x1,y1) > e^u(x2,y2)."

"Another way to put this is that there are no natural units for utility, at least until 
such time as we are able to measure pleasure in the brain. [Any increasing
transformation is acceptable.]"

"It is possible to develop the theory of consumer choice without supposing that a 
utility function exists at all. However, it is expedient to begin with utility, to 
simplify the analysis for introductory purposes."

A discussion of the concept of economic utility from investopedia:
https://www.investopedia.com/ask/answers/032615/what-are-four-types-economic-utility.asp

"The four types of economic utility are form, time, place, and possession, whereby utility 
refers to the usefulness or value that consumers experience from a product. The 
economic utilities help assess consumer purchase decisions and pinpoint the drivers 
behind those decisions."

"Companies strive to increase the utility or perceived value of their products and services 
to enhance customer satisfaction, increase sales, and drive earnings. The concept of 
economic utility falls under the area of study known as behavioral economics. It is 
designed to assist companies in operating a business and marketing the company in a 
way that is likely to attract the maximum amount of customers and sales revenues."

Form utility
"Form utility refers to how well a product or service meets the customer's needs. For 
example, a company might design a product to target a specific client's needs or wants. 
Form utility is the incorporation of customer needs and wants into the features and 
benefits of the products being offered by the company."

"Companies invest time and money into product research to pinpoint exactly what products 
or services consumers desire. From there, company executives strategize on the 
development of the product with the goal of meeting or exceeding those needs to create 
form utility."

"Form utility might include offering consumers lower prices, more convenience, or a wider 
selection of products. The goal of these efforts is to increase and maximize the perceived
 value of the products."

Time utility
"Time utility exists when a company maximizes the availability of a product so that 
customers can buy it during the times that are the most convenient or desirable for them.
 Companies analyze how to create or maximize their products' time utility and adjust 
their production process, logistical planning of manufacturing, and delivery."

"Creating time utility includes considering the hours and days of the week a company 
might choose to make its services available. For example, a store might open on the 
weekends if customers typically shop for that product at that time. Time utility might 
also include 24-hour availability for a product or the company's customer service 
department through a phone number or website chat function."

Place utility
"Place utility refers primarily to making goods or services physically available or 
accessible to potential customers. Examples of place utility range from a retail store's 
location to how easy a company's website or services are to find on the internet. 
Companies that have effective search engine optimization or SEO strategies can improve
 their place utility. SEO is the process of increasing a website's availability to internet 
users through their searches on the web."

"Increasing convenience for customers can be a key element in attracting business. 
A company that offers easy access to technical assistance offers an added value in 
comparison to a similar company that does not offer a similar service. Making a product 
available in a wide variety of stores and locations is considered an added value since its 
more convenient. For example, Apple Inc. sells iPhones and laptops through its retail 
stores, but also offers its products through other electronics retailers, including 
Best Buy Co. Inc." 

Possession utility
"Possession utility is the amount of usefulness or perceived value from owning a product.
 For example, owning a car or truck might be considered to have a high possession utility.
 Also, increasing the ease of ownership boosts the possession utility or the perceived 
value of a product. For example, offering favorable financing terms toward ownership 
of a car, appliance, or home would likely create possession utility for those products 
and lead to increased sales."

More about economic utility from:
https://www.geektonight.com/utility-in-economics/

"Utility is that invisible quality of anything which resorts to satisfying any human want. The 
utility may neither be seen, i.e. it is invisible, nor may it be touched. It is there in the things 
in abstract or invisible form."

"Utility is not concerned with the ‘morality’. Whether the consumption of a thing is useful or 
harmful, if it serves to fulfill the wants of anyone, it possesses ‘utility’."

"Utility emerges out of the human needs or wants. Thus it is Individual and relative in nature.
It is a subjective concept, not objective or concrete which could be uniformly applicable in 
all cases."

"Mathematically, utility can be expressed as a function of the quantities of different 
commodities consumed by an individual."

"If an individual consumes quantity m1 of a commodity M, quantity n1 of a commodity N, 
and quantity r1 of a commodity R, the (total) utility U of the consumer can be measured 
as follows:
    U = f (m1, n1, r1)."

Marginal Utility
"Marginal utility is defined as the utility derived from the marginal or additional unit of a 
commodity consumed by an individual."

"It can also be defined as the addition to the total utility of a commodity resulting from the 
consumption of an additional unit."

"Therefore, marginal utility, MU of a commodity X, is the change in the total utility, ∆TU, 
attained from the consumption of an additional unit of commodity X."

From N. Gregory Mankiw, Principles of Economics, 9th ed., 2021, (Kindle ver), p 430

"Utility: An Alternative Way to Describe Preferences and Optimization."

"We have used indifference curves to represent the consumer’s preferences. Another 
common way to represent preferences is with the concept of utility. Utility is an abstract 
measure of the satisfaction or happiness that a consumer receives from a bundle of 
goods. Economists say that a consumer prefers one bundle of goods to another if it 
provides more utility than the other."

"Indifference curves and utility are closely related. Because the consumer prefers points 
on higher indifference curves, bundles of goods on higher indifference curves provide 
higher utility. Because the consumer is equally happy with all points on the same 
indifference curve, all these bundles provide the same utility. You can think of an 
indifference curve as an “equal-utility” curve."

"The 'marginal utility' of any good is the increase in utility that the consumer gets from an 
additional unit of that good. Most goods are assumed to exhibit diminishing marginal utility: 
The more of the good the consumer already has, the lower the marginal utility provided by 
an extra unit of that good."

"The 'marginal rate of substitution', MRS, between two goods depends on their marginal 
utilities. For example, if the marginal utility of good X is twice the marginal utility of good Y,
 then a person would need 2 units of good Y to compensate for losing 1 unit of good X, 
and the MRS equals 2. More generally, the marginal rate of substitution (and thus the 
slope of the indifference curve) equals the marginal utility of one good divided by the 
marginal utility of the other good."

                MRS = MUx/MUy
  
"Utility analysis provides another way to describe consumer optimization. Recall that, at 
the consumer’s optimum, the 'marginal rate of substitution' equals the ratio of prices."
That is 
                MRS = Px/Py.

Because the 'marginal rate of substitution' MRS equals the ratio of marginal utilities, we 
can write this condition for optimization as

              MUx/MUy = Px/Py.

Now rearrange this equation to get

              MUx/Px  = MUy/Py."

"This equation has a simple interpretation: At the optimum, the marginal utility per dollar 
spent on good X equals the marginal utility per dollar spent on good Y. If this equality 
did not hold, the consumer could increase her utility by spending less on the good that 
provided lower marginal utility per dollar and more on the good that provided higher 
marginal utility per dollar."

### Problem 6.36 Maximize Utility with Budget Constraint

a) Given the utility function u = Q1*Q2 and per unit prices P1 = 1, P2 = 4, and given the 
budget limit B = 120, what is the optimum solution based on maximizing the utility function?

Let g = P1*Q1 + P2*Q2 = Q1 + 4*Q2 = money spent on goods Q1 and Q2. The budget 
constraint can then be written as 120 - g = 0. optimum prints out the lagrangian used
internally (lam[1] is the Lagrange multiplier symbol used by optimum here), and prints
out two lines for the same solution, the second line being the floating point version of the
first line.

killAB()$
u : Q1*Q2;
g : Q1 + 4*Q2;
optimum (u, [Q1, Q2], 120 - g);

optimum produces a global list cp.

cp;

cp1 : cp[1];

critPt : rest (cp1, -1);

at (u, critPt);

optimum has found a relative maximum of the objective function at Q1 = 60, Q2 = 15.
The Lagrange multiplier value found for this solution is 15, which means if we increase the
budget by one dollar, from 120 to 121, the value of the utility increases by about $15.
Thus the marginal utility of money (or income) at Q1 = 60, Q2 = 15, is approximately 15.

optimum (u, [Q1, Q2], 121 - g);

We see from the new optimum solution with B = 121 that u has increased from 900 to 
915.06 so Δu ~ 15.

"DO IT YOURSELF"

Let L be the Lagrangian function, λ be the Lagrangian multiplier.

L : u + λ*(120 - g);
gradL : jacobian ([L], [Q1, Q2, λ])[1];
solns : solve (gradL, [Q1, Q2, λ]);

critPt : rest (solns[1], -1);

at (u, critPt);