Skip to content

Commit 541a962

Browse files
committed
@mmcky review in jupyter lab, standardise colors + math updates
1 parent b254d3a commit 541a962

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

lectures/intro_supply_demand.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.15.2
7+
jupytext_version: 1.15.1
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -98,7 +98,6 @@ The total height of each bar $i$ is willingness to pay by consumer $i$.
9898

9999
The orange portion of some of the bars shows consumer surplus.
100100

101-
102101
```{code-cell} ipython3
103102
fig, ax = plt.subplots()
104103
consumers = range(1, 11) # consumers 1,..., 10
@@ -165,7 +164,7 @@ q_grid = np.linspace(q_min, q_max, 1000)
165164
fig, ax = plt.subplots()
166165
ax.plot((q_min, q_max), (price, price), lw=2, label="price")
167166
ax.plot(q_grid, inverse_demand(q_grid),
168-
color="k", label="inverse demand curve")
167+
color="orange", label="inverse demand curve")
169168
ax.set_ylabel("willingness to pay, price")
170169
ax.set_xlabel("quantity")
171170
ax.set_xlim(q_min, q_max)
@@ -185,11 +184,11 @@ q_star = np.log(100) - np.log(price)
185184
fig, ax = plt.subplots()
186185
ax.plot((q_min, q_max), (price, price), lw=2, label="price")
187186
ax.plot(q_grid, inverse_demand(q_grid),
188-
color="k", label="inverse demand curve")
187+
color="orange", label="inverse demand curve")
189188
small_grid = np.linspace(0, q_star, 500)
190189
ax.fill_between(small_grid, np.full(len(small_grid), price),
191-
inverse_demand(small_grid), color="darkorange",
192-
alpha=0.6, label="consumer surplus")
190+
inverse_demand(small_grid), color="orange",
191+
alpha=0.5, label="consumer surplus")
193192
ax.vlines(q_star, 0, price, ls="--")
194193
ax.set_ylabel("willingness to pay, price")
195194
ax.set_xlabel("quantity")
@@ -261,12 +260,12 @@ q_star = (price / 2)**(1/2)
261260
fig, ax = plt.subplots()
262261
ax.plot((q_min, q_max), (price, price), lw=2, label="price")
263262
ax.plot(q_grid, inverse_supply(q_grid),
264-
color="k", label="inverse supply curve")
263+
color="green", label="inverse supply curve")
265264
small_grid = np.linspace(0, q_star, 500)
266265
ax.fill_between(small_grid, inverse_supply(small_grid),
267266
np.full(len(small_grid), price),
268-
color="darkgreen",
269-
alpha=0.4, label="producer surplus")
267+
color="green",
268+
alpha=0.5, label="producer surplus")
270269
ax.vlines(q_star, 0, price, ls="--")
271270
ax.set_ylabel("willingness to sell, price")
272271
ax.set_xlabel("quantity")
@@ -289,7 +288,7 @@ For those who are not, here is a quick introduction.
289288

290289
In general, for a function $f$, the **integral** of $f$ over the interval $[a, b]$ is the area under the curve $f$ between $a$ and $b$.
291290

292-
This value is written as $\int_a^b f(x) dx$ and illustrated in the figure below when $f(x) = \cos(x/2) + 1$.
291+
This value is written as $\int_a^b f(x) \mathrm{d} x$ and illustrated in the figure below when $f(x) = \cos(x/2) + 1$.
293292

294293
```{code-cell} ipython3
295294
def f(x):
@@ -303,7 +302,8 @@ ab_grid = np.linspace(a, b, 400)
303302
fig, ax = plt.subplots()
304303
ax.plot(x_grid, f(x_grid), label="$f$", color="k")
305304
ax.fill_between(ab_grid, [0] * len(ab_grid), f(ab_grid),
306-
alpha=0.5, label="$\int_a^b f(x) dx$")
305+
label="$\int_a^b f(x) dx$",
306+
color='grey', alpha=0.5)
307307
ax.legend()
308308
plt.show()
309309
```
@@ -314,10 +314,10 @@ Many of these rules relate to one of the most beautiful and powerful results in
314314

315315
We will not try to cover these ideas here, partly because the subject is too big, and partly because you only need to know one rule for this lecture, stated below.
316316

317-
If $f(x) = c + d x$, then
317+
If $f(x) = c + \mathrm{d} x$, then
318318

319319
$$
320-
\int_a^b f(x) dx = c (b - a) + \frac{d}{2}(b^2 - a^2)
320+
\int_a^b f(x) \mathrm{d} x = c (b - a) + \frac{d}{2}(b^2 - a^2)
321321
$$
322322

323323
In fact this rule is so simple that it can be calculated from elementary geometry -- you might like to try by graphing $f$ and calculating the area under the curve between $a$ and $b$.
@@ -397,8 +397,8 @@ supply_curve = market.inverse_supply(q_grid)
397397
demand_curve = market.inverse_demand(q_grid)
398398
399399
fig, ax = plt.subplots()
400-
ax.plot(q_grid, supply_curve, label='supply')
401-
ax.plot(q_grid, demand_curve, label='demand')
400+
ax.plot(q_grid, supply_curve, label='supply', color='green')
401+
ax.plot(q_grid, demand_curve, label='demand', color='orange')
402402
ax.legend(loc='upper center', frameon=False)
403403
ax.set_ylim(0, 1.2)
404404
ax.set_xticks((0, 1))
@@ -420,7 +420,7 @@ curve minus $p q$:
420420

421421
$$
422422
S_c(q) :=
423-
\int_0^{q} (d_0 - d_1 x) dx - p q
423+
\int_0^{q} (d_0 - d_1 x) \mathrm{d} x - p q
424424
$$ (eq:cstm_spls)
425425
426426
The next figure illustrates
@@ -433,12 +433,13 @@ p = market.inverse_demand(q)
433433
ps = np.ones_like(q_grid) * p
434434
435435
fig, ax = plt.subplots()
436-
ax.plot(q_grid, demand_curve, label='demand')
436+
ax.plot(q_grid, demand_curve, label='demand', color='orange')
437437
ax.fill_between(q_grid[q_grid <= q],
438438
demand_curve[q_grid <= q],
439439
ps[q_grid <= q],
440440
label='consumer surplus',
441-
color='#EED1CF')
441+
color="orange",
442+
alpha=0.5)
442443
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
443444
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)
444445
@@ -479,7 +480,7 @@ We define **producer surplus** as $p q$ minus the area under an inverse supply c
479480
480481
$$
481482
S_p(q)
482-
:= p q - \int_0^q (s_0 + s_1 x) dx
483+
:= p q - \int_0^q (s_0 + s_1 x) \mathrm{d} x
483484
$$ (eq:pdcr_spls)
484485
485486
The next figure illustrates
@@ -492,12 +493,13 @@ p = market.inverse_supply(q)
492493
ps = np.ones_like(q_grid) * p
493494
494495
fig, ax = plt.subplots()
495-
ax.plot(q_grid, supply_curve, label='supply')
496+
ax.plot(q_grid, supply_curve, label='supply', color='green')
496497
ax.fill_between(q_grid[q_grid <= q],
497498
supply_curve[q_grid <= q],
498499
ps[q_grid <= q],
499500
label='producer surplus',
500-
color='#E6E6F5')
501+
color="green",
502+
alpha=0.5)
501503
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
502504
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)
503505
@@ -538,7 +540,7 @@ producers pay the same price:
538540
539541
$$
540542
W(q)
541-
= \int_0^q (d_0 - d_1 x) dx - \int_0^q (s_0 + s_1 x) dx
543+
= \int_0^q (d_0 - d_1 x) dx - \int_0^q (s_0 + s_1 x) \mathrm{d} x
542544
$$
543545
544546
Evaluating the integrals gives
@@ -565,7 +567,7 @@ The next figure plots welfare as a function of $q$.
565567
566568
q_vals = np.linspace(0, 1.78, 200)
567569
fig, ax = plt.subplots()
568-
ax.plot(q_vals, W(q_vals, market), label='welfare')
570+
ax.plot(q_vals, W(q_vals, market), label='welfare', color='brown')
569571
ax.legend(frameon=False)
570572
ax.set_xlabel('quantity')
571573
plt.show()
@@ -577,7 +579,7 @@ To compute a quantity that maximizes the welfare criterion, we differentiate
577579
$W$ with respect to $q$ and then set the derivative to zero.
578580
579581
$$
580-
\frac{d W(q)}{d q} = d_0 - s_0 - (d_1 + s_1) q = 0
582+
\frac{\mathrm{d} W(q)}{\mathrm{d} q} = d_0 - s_0 - (d_1 + s_1) q = 0
581583
$$
582584
583585
Solving for $q$ yields
@@ -704,8 +706,8 @@ supply_curve = market.inverse_supply(q_grid)
704706
demand_curve = market.inverse_demand(q_grid)
705707
706708
fig, ax = plt.subplots()
707-
ax.plot(q_grid, supply_curve, label='supply')
708-
ax.plot(q_grid, demand_curve, label='demand')
709+
ax.plot(q_grid, supply_curve, label='supply', color='green')
710+
ax.plot(q_grid, demand_curve, label='demand', color='orange')
709711
ax.legend(loc='upper center', frameon=False)
710712
ax.set_ylim(0, 1.2)
711713
ax.set_xticks((0, 1))
@@ -736,7 +738,7 @@ supply curve:
736738
737739
$$
738740
S_p(q)
739-
= p q - \int_0^q i_s(x) dx
741+
= p q - \int_0^q i_s(x) \mathrm{d} x
740742
$$
741743
742744
Here $p$ is set to $i_s(q)$.
@@ -746,7 +748,7 @@ assumption that the price is the same for buyers and sellers:
746748
747749
$$
748750
W(q)
749-
= \int_0^q i_d(x) dx - \int_0^q i_s(x) dx
751+
= \int_0^q i_d(x) dx - \int_0^q i_s(x) \mathrm{d} x
750752
$$
751753
752754
Solve the integrals and write a function to compute this quantity numerically
@@ -786,7 +788,7 @@ The next figure plots welfare as a function of $q$.
786788
787789
```{code-cell} ipython3
788790
fig, ax = plt.subplots()
789-
ax.plot(q_vals, W(q_vals, market), label='welfare')
791+
ax.plot(q_vals, W(q_vals, market), label='welfare', color='brown')
790792
ax.legend(frameon=False)
791793
ax.set_xlabel('quantity')
792794
plt.show()

0 commit comments

Comments
 (0)