Skip to content

Commit 72d4db7

Browse files
authored
Merge pull request #278 from QuantEcon/review_supply_demand
Review supply demand
2 parents c556397 + 00fb34f commit 72d4db7

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

lectures/intro_supply_demand.md

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ jupytext:
33
text_representation:
44
extension: .md
55
format_name: myst
6+
format_version: 0.13
7+
jupytext_version: 1.11.5
68
kernelspec:
79
display_name: Python 3 (ipykernel)
810
language: python
@@ -11,7 +13,7 @@ kernelspec:
1113

1214
# Introduction to Supply and Demand
1315

14-
## Outline
16+
## Overview
1517

1618
This lecture is about some models of equilibrium prices and quantities, one of
1719
the main topics of elementary microeconomics.
@@ -31,9 +33,9 @@ Key infrastructure concepts that we'll encounter in this lecture are
3133
* social welfare as the sum of consumer and producer surpluses
3234
* relationship between equilibrium quantity and social welfare optimum
3335

34-
Throughout the lectures, we'll assume that inverse demand and supply curves are **affine** functions of output.
36+
Throughout the lectures, we'll assume that inverse demand and supply curves are **affine** functions of quantity.
3537

36-
("Affine" means "linear plus a constant".)
38+
("Affine" means "linear plus a constant" and [here](https://math.stackexchange.com/questions/275310/what-is-the-difference-between-linear-and-affine-function) is a nice discussion about it.)
3739

3840
We'll also assume affine inverse supply and demand functions when we study models with multiple consumption goods in our {doc}`subsequent lecture <supply_demand_multiple_goods>`.
3941

@@ -46,7 +48,6 @@ import numpy as np
4648
import matplotlib.pyplot as plt
4749
```
4850

49-
5051
## Supply and demand
5152

5253
We study a market for a single good in which buyers and sellers exchange a quantity $q$ for a price $p$.
@@ -73,11 +74,11 @@ implementing the inverse demand and supply curves.
7374
```{code-cell} ipython3
7475
class Market:
7576
76-
def __init__(self,
77-
d_0=1.0, # demand intercept
78-
d_1=0.6, # demand slope
79-
s_0=0.1, # supply intercept
80-
s_1=0.4): # supply slope
77+
def __init__(self,
78+
d_0=1.0, # demand intercept
79+
d_1=0.6, # demand slope
80+
s_0=0.1, # supply intercept
81+
s_1=0.4): # supply slope
8182
8283
self.d_0, self.d_1 = d_0, d_1
8384
self.s_0, self.s_1 = s_0, s_1
@@ -87,22 +88,19 @@ class Market:
8788
8889
def inverse_supply(self, q):
8990
return self.s_0 + self.s_1 * q
90-
9191
```
9292

93-
94-
9593
Let's create an instance.
9694

9795
```{code-cell} ipython3
9896
market = Market()
9997
```
10098

101-
10299
Here is a plot of these two functions using `market`.
103100

104101
```{code-cell} ipython3
105102
:tags: [hide-input]
103+
106104
market = Market()
107105
108106
grid_min, grid_max, grid_size = 0, 1.5, 200
@@ -122,7 +120,7 @@ ax.set_ylabel('price')
122120
plt.show()
123121
```
124122

125-
In the above graph, an **equilibrium** price, quantity pair occurs at the intersection of the supply and demand curves.
123+
In the above graph, an **equilibrium** price-quantity pair occurs at the intersection of the supply and demand curves.
126124

127125
### Consumer surplus
128126

@@ -135,7 +133,7 @@ curve minus $p q$:
135133
$$
136134
S_c(q) :=
137135
\int_0^{q} (d_0 - d_1 x) dx - p q
138-
$$
136+
$$ (eq:cstm_spls)
139137
140138
The next figure illustrates
141139
@@ -149,11 +147,11 @@ ps = np.ones_like(q_grid) * p
149147
150148
fig, ax = plt.subplots()
151149
ax.plot(q_grid, demand_curve, label='demand')
152-
ax.fill_between(q_grid[q_grid <= q],
153-
demand_curve[q_grid<=q],
154-
ps[q_grid <= q],
155-
label='consumer surplus',
156-
color='#EED1CF')
150+
ax.fill_between(q_grid[q_grid <= q],
151+
demand_curve[q_grid <= q],
152+
ps[q_grid <= q],
153+
label='consumer surplus',
154+
color='#EED1CF')
157155
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
158156
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)
159157
@@ -168,18 +166,17 @@ ax.set_ylabel('price')
168166
plt.show()
169167
```
170168
171-
172169
Consumer surplus provides a measure of total consumer welfare at quantity $q$.
173170
174171
The idea is that the inverse demand curve $d_0 - d_1 q$ shows a consumer's willingness to
175-
pay for an additional increment of the good at a given quantity $q$.
172+
pay for an additional increment of the good at a given quantity $q$.
176173
177174
The difference between willingness to pay and the actual price is consumer surplus.
178175
179176
The value $S_c(q)$ is the "sum" (i.e., integral) of these surpluses when the total
180177
quantity purchased is $q$ and the purchase price is $p$.
181178
182-
Evaluating the integral in the definition of consumer surplus gives
179+
Evaluating the integral in the definition of consumer surplus {eq}`eq:cstm_spls` gives
183180
184181
$$
185182
S_c(q)
@@ -200,7 +197,7 @@ We define **producer surplus** as $p q$ minus the area under an inverse supply c
200197
$$
201198
S_p(q)
202199
:= p q - \int_0^q (s_0 + s_1 x) dx
203-
$$
200+
$$ (eq:pdcr_spls)
204201
205202
The next figure illustrates
206203
@@ -213,11 +210,11 @@ ps = np.ones_like(q_grid) * p
213210
214211
fig, ax = plt.subplots()
215212
ax.plot(q_grid, supply_curve, label='supply')
216-
ax.fill_between(q_grid[q_grid <= q],
217-
supply_curve[q_grid<=q],
218-
ps[q_grid <= q],
219-
label='producer surplus',
220-
color='#E6E6F5')
213+
ax.fill_between(q_grid[q_grid <= q],
214+
supply_curve[q_grid <= q],
215+
ps[q_grid <= q],
216+
label='producer surplus',
217+
color='#E6E6F5')
221218
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
222219
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)
223220
@@ -243,7 +240,7 @@ The difference between willingness to sell and the actual price is producer surp
243240
244241
The value $S_p(q)$ is the integral of these surpluses.
245242
246-
Evaluating the integral in the definition of consumer surplus gives
243+
Evaluating the integral in the definition of producer surplus {eq}`eq:pdcr_spls` gives
247244
248245
$$
249246
S_p(q) = pq - s_0 q - \frac{1}{2} s_1 q^2
@@ -275,14 +272,15 @@ def W(q, market):
275272
# Unpack
276273
d_0, d_1, s_0, s_1 = market.d_0, market.d_1, market.s_0, market.s_1
277274
# Compute and return welfare
278-
return (d_0 - s_0) * q - 0.5 * (d_1 + s_1) * q**2
275+
return (d_0 - s_0) * q - 0.5 * (d_1 + s_1) * q**2
279276
```
280277
281278
The next figure plots welfare as a function of $q$.
282279
283280
284281
```{code-cell} ipython3
285282
:tags: [hide-input]
283+
286284
q_vals = np.linspace(0, 1.78, 200)
287285
fig, ax = plt.subplots()
288286
ax.plot(q_vals, W(q_vals, market), label='welfare')
@@ -394,11 +392,11 @@ Using the class, plot the inverse demand and supply curves $i_d$ and $i_s$
394392
```{code-cell} ipython3
395393
class Market:
396394
397-
def __init__(self,
398-
d_0=1.0, # demand intercept
399-
d_1=0.6, # demand slope
400-
s_0=0.1, # supply intercept
401-
s_1=0.4): # supply slope
395+
def __init__(self,
396+
d_0=1.0, # demand intercept
397+
d_1=0.6, # demand slope
398+
s_0=0.1, # supply intercept
399+
s_1=0.4): # supply slope
402400
403401
self.d_0, self.d_1 = d_0, d_1
404402
self.s_0, self.s_1 = s_0, s_1
@@ -408,7 +406,6 @@ class Market:
408406
409407
def inverse_supply(self, q):
410408
return self.s_0 + self.s_1 * q**1.8
411-
412409
```
413410
414411
Let's create an instance.
@@ -498,7 +495,8 @@ Here's a Python function that computes this value:
498495
```{code-cell} ipython3
499496
def W(q, market):
500497
# Unpack
501-
d_0, d_1, s_0, s_1 = market.d_0, market.d_1, market.s_0, market.s_1
498+
d_0, d_1 = market.d_0, market.d_1
499+
s_0, s_1 = market.s_0, market.s_1
502500
# Compute and return welfare
503501
S_c = d_0 * q - d_1 * q**1.6 / 1.6
504502
S_p = s_0 * q + s_1 * q**2.8 / 2.8
@@ -577,7 +575,7 @@ price, in line with the first fundamental welfare theorem.
577575
```
578576
579577
580-
```{solution-start} isd_ex3
578+
```{solution-start} isd_ex4
581579
:class: dropdown
582580
```
583581

0 commit comments

Comments
 (0)