Skip to content

Commit aeb306c

Browse files
Fix supply demand (#176)
* Capitalize headings * Change ^T to ^\top * Fix camel case for classes * Check grammar * Remove reduntent white spaces * Fix minor layout issues * Add ipython config * Unify code format * Fix minor typos --------- Co-authored-by: HengCheng <[email protected]>
1 parent 634af8a commit aeb306c

File tree

3 files changed

+268
-261
lines changed

3 files changed

+268
-261
lines changed

lectures/intro_supply_demand.md

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ import matplotlib.pyplot as plt
5757

5858
## Supply and Demand
5959

60-
We study a market for a single good in which buyers and sellers exchange a quantity $q$ for a price $p$.
60+
We study a market for a single good in which buyers and sellers exchange a quantity $q$ for a price $p$.
6161

62-
Quantity $q$ and price $p$ are both scalars.
62+
Quantity $q$ and price $p$ are both scalars.
6363

6464
We assume that inverse demand and supply curves for the good are:
6565

@@ -177,7 +177,7 @@ plt.show()
177177

178178
Consumer surplus gives a measure of total consumer welfare at quantity $q$.
179179

180-
The idea is that the inverse demand curve $d_0 - d_1 q$ shows willingness to
180+
The idea is that the inverse demand curve $d_0 - d_1 q$ shows willingness to
181181
pay at a given quantity $q$.
182182

183183
The difference between willingness to pay and the actual price is the surplus.
@@ -312,16 +312,15 @@ $$
312312
q = \frac{ d_0 - s_0}{s_1 + d_1}
313313
$$ (eq:old1)
314314
315-
Let's remember the quantity $q$ given by equation {eq}`eq:old1` that a social planner would choose to maximize consumer plus producer surplus.
315+
Let's remember the quantity $q$ given by equation {eq}`eq:old1` that a social planner would choose to maximize consumer surplus plus producer surplus.
316316
317-
We'll compare it to the quantity that emerges in a competitive equilibrium
318-
equilibrium that equates supply to demand.
317+
We'll compare it to the quantity that emerges in a competitive equilibrium that equates supply to demand.
319318
320319
321320
322321
### Competitive Equilibrium
323322
324-
Instead of equating quantities supplied and demanded, we'll can accomplish the
323+
Instead of equating quantities supplied and demanded, we can accomplish the
325324
same thing by equating demand price to supply price:
326325
327326
$$
@@ -347,29 +346,24 @@ supply to demand brings us a **key finding:**
347346
348347
This is a version of the [first fundamental welfare theorem](https://en.wikipedia.org/wiki/Fundamental_theorems_of_welfare_economics),
349348
350-
It also brings a useful **competitive equilibrium computation strategy:**
351-
352-
* after solving the welfare problem for an optimal quantity, we can read a
353-
competitive equilibrium price from either supply price or demand price at
354-
the competitive equilibrium quantity
349+
It also brings a useful **competitive equilibrium computation strategy:**
355350
351+
* after solving the welfare problem for an optimal quantity, we can read a competitive equilibrium price from either supply price or demand price at the competitive equilibrium quantity
356352
357353
## Generalizations
358354
359-
In a {doc}`later lecture <supply_demand_multiple_goods>`, we'll derive
355+
In a {doc}`later lecture <supply_demand_multiple_goods>`, we'll derive
360356
generalizations of the above demand and supply curves from other objects.
361357
362-
Our generalizations will extend the preceding analysis of a market for a
363-
single good to the analysis of $n$ simultaneous markets in $n$ goods.
358+
Our generalizations will extend the preceding analysis of a market for a single good to the analysis of $n$ simultaneous markets in $n$ goods.
364359
365360
In addition
366361
367362
* we'll derive **demand curves** from a consumer problem that maximizes a
368363
**utility function** subject to a **budget constraint**.
369364
370365
* we'll derive **supply curves** from the problem of a producer who is price
371-
taker and maximizes his profits minus total costs that are described by a
372-
**cost function**.
366+
taker and maximizes his profits minus total costs that are described by a **cost function**.
373367
374368
## Exercises
375369
@@ -387,21 +381,18 @@ $$
387381
All parameters are positive, as before.
388382
389383
390-
391-
392384
```{exercise}
393385
:label: isd_ex1
394386
395387
Define a new `Market` class that holds the same parameter values as before by
396-
changes the `inverse_demand` and `inverse_supply` methods to
388+
changing the `inverse_demand` and `inverse_supply` methods to
397389
match these new definitions.
398390
399391
Using the class, plot the inverse demand and supply curves $i_d$ and $i_s$
400392
401393
```
402394
403395
404-
405396
```{solution-start} isd_ex1
406397
:class: dropdown
407398
```
@@ -432,7 +423,6 @@ Let's create an instance.
432423
market = Market()
433424
```
434425
435-
436426
Here is a plot of inverse supply and demand.
437427
438428
```{code-cell} ipython3
@@ -455,16 +445,13 @@ ax.set_ylabel('price')
455445
plt.show()
456446
```
457447
458-
459448
```{solution-end}
460449
```
461450
462451
463-
464452
```{exercise}
465453
:label: isd_ex2
466454
467-
468455
As before, consumer surplus at $q$ is the area under the demand curve minus
469456
price times quantity:
470457
@@ -500,7 +487,6 @@ Plot welfare as a function of $q$.
500487
```
501488
502489
503-
504490
```{solution-start} isd_ex2
505491
:class: dropdown
506492
```
@@ -515,7 +501,6 @@ $$
515501
516502
Here's a Python function that computes this value:
517503
518-
519504
```{code-cell} ipython3
520505
def W(q, market):
521506
# Unpack
@@ -528,7 +513,6 @@ def W(q, market):
528513
529514
The next figure plots welfare as a function of $q$.
530515
531-
532516
```{code-cell} ipython3
533517
fig, ax = plt.subplots()
534518
ax.plot(q_vals, W(q_vals, market), label='welfare')
@@ -541,11 +525,9 @@ plt.show()
541525
```
542526
543527
544-
545528
```{exercise}
546529
:label: isd_ex3
547530
548-
549531
Due to nonlinearities, the new welfare function is not easy to maximize with
550532
pencil and paper.
551533
@@ -554,7 +536,6 @@ Maximize it using `scipy.optimize.minimize_scalar` instead.
554536
```
555537
556538
557-
558539
```{solution-start} isd_ex3
559540
:class: dropdown
560541
```
@@ -569,8 +550,6 @@ result = minimize_scalar(objective, bounds=(0, 10))
569550
print(result.message)
570551
```
571552
572-
573-
574553
```{code-cell} ipython3
575554
maximizing_q = result.x
576555
print(f"{maximizing_q: .5f}")
@@ -580,7 +559,6 @@ print(f"{maximizing_q: .5f}")
580559
```
581560
582561
583-
584562
```{exercise}
585563
:label: isd_ex4
586564
@@ -605,12 +583,10 @@ price, in line with the first fundamental welfare theorem.
605583
```
606584
607585
608-
609586
```{solution-start} isd_ex3
610587
:class: dropdown
611588
```
612589
613-
614590
```{code-cell} ipython3
615591
from scipy.optimize import newton
616592
@@ -621,7 +597,5 @@ equilibrium_q = newton(excess_demand, 0.1)
621597
print(f"{equilibrium_q: .5f}")
622598
```
623599
624-
625600
```{solution-end}
626601
```
627-

0 commit comments

Comments
 (0)