@@ -4,7 +4,7 @@ jupytext:
4
4
extension : .md
5
5
format_name : myst
6
6
format_version : 0.13
7
- jupytext_version : 1.15.2
7
+ jupytext_version : 1.15.1
8
8
kernelspec :
9
9
display_name : Python 3 (ipykernel)
10
10
language : python
@@ -98,7 +98,6 @@ The total height of each bar $i$ is willingness to pay by consumer $i$.
98
98
99
99
The orange portion of some of the bars shows consumer surplus.
100
100
101
-
102
101
``` {code-cell} ipython3
103
102
fig, ax = plt.subplots()
104
103
consumers = range(1, 11) # consumers 1,..., 10
@@ -165,7 +164,7 @@ q_grid = np.linspace(q_min, q_max, 1000)
165
164
fig, ax = plt.subplots()
166
165
ax.plot((q_min, q_max), (price, price), lw=2, label="price")
167
166
ax.plot(q_grid, inverse_demand(q_grid),
168
- color="k ", label="inverse demand curve")
167
+ color="orange ", label="inverse demand curve")
169
168
ax.set_ylabel("willingness to pay, price")
170
169
ax.set_xlabel("quantity")
171
170
ax.set_xlim(q_min, q_max)
@@ -185,11 +184,11 @@ q_star = np.log(100) - np.log(price)
185
184
fig, ax = plt.subplots()
186
185
ax.plot((q_min, q_max), (price, price), lw=2, label="price")
187
186
ax.plot(q_grid, inverse_demand(q_grid),
188
- color="k ", label="inverse demand curve")
187
+ color="orange ", label="inverse demand curve")
189
188
small_grid = np.linspace(0, q_star, 500)
190
189
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")
193
192
ax.vlines(q_star, 0, price, ls="--")
194
193
ax.set_ylabel("willingness to pay, price")
195
194
ax.set_xlabel("quantity")
@@ -261,12 +260,12 @@ q_star = (price / 2)**(1/2)
261
260
fig, ax = plt.subplots()
262
261
ax.plot((q_min, q_max), (price, price), lw=2, label="price")
263
262
ax.plot(q_grid, inverse_supply(q_grid),
264
- color="k ", label="inverse supply curve")
263
+ color="green ", label="inverse supply curve")
265
264
small_grid = np.linspace(0, q_star, 500)
266
265
ax.fill_between(small_grid, inverse_supply(small_grid),
267
266
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")
270
269
ax.vlines(q_star, 0, price, ls="--")
271
270
ax.set_ylabel("willingness to sell, price")
272
271
ax.set_xlabel("quantity")
@@ -289,7 +288,7 @@ For those who are not, here is a quick introduction.
289
288
290
289
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$.
291
290
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$.
293
292
294
293
``` {code-cell} ipython3
295
294
def f(x):
@@ -303,7 +302,8 @@ ab_grid = np.linspace(a, b, 400)
303
302
fig, ax = plt.subplots()
304
303
ax.plot(x_grid, f(x_grid), label="$f$", color="k")
305
304
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)
307
307
ax.legend()
308
308
plt.show()
309
309
```
@@ -314,10 +314,10 @@ Many of these rules relate to one of the most beautiful and powerful results in
314
314
315
315
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.
316
316
317
- If $f(x) = c + d x$, then
317
+ If $f(x) = c + \mathrm{d} x$, then
318
318
319
319
$$
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)
321
321
$$
322
322
323
323
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)
397
397
demand_curve = market.inverse_demand(q_grid)
398
398
399
399
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' )
402
402
ax.legend(loc='upper center', frameon=False)
403
403
ax.set_ylim(0, 1.2)
404
404
ax.set_xticks((0, 1))
@@ -420,7 +420,7 @@ curve minus $p q$:
420
420
421
421
$$
422
422
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
424
424
$$ (eq:cstm_spls)
425
425
426
426
The next figure illustrates
@@ -433,12 +433,13 @@ p = market.inverse_demand(q)
433
433
ps = np.ones_like(q_grid) * p
434
434
435
435
fig, ax = plt.subplots()
436
- ax.plot(q_grid, demand_curve, label='demand')
436
+ ax.plot(q_grid, demand_curve, label='demand', color='orange' )
437
437
ax.fill_between(q_grid[q_grid <= q],
438
438
demand_curve[q_grid <= q],
439
439
ps[q_grid <= q],
440
440
label='consumer surplus',
441
- color='#EED1CF')
441
+ color="orange",
442
+ alpha=0.5)
442
443
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
443
444
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)
444
445
@@ -479,7 +480,7 @@ We define **producer surplus** as $p q$ minus the area under an inverse supply c
479
480
480
481
$$
481
482
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
483
484
$$ (eq:pdcr_spls)
484
485
485
486
The next figure illustrates
@@ -492,12 +493,13 @@ p = market.inverse_supply(q)
492
493
ps = np.ones_like(q_grid) * p
493
494
494
495
fig, ax = plt.subplots()
495
- ax.plot(q_grid, supply_curve, label='supply')
496
+ ax.plot(q_grid, supply_curve, label='supply', color='green' )
496
497
ax.fill_between(q_grid[q_grid <= q],
497
498
supply_curve[q_grid <= q],
498
499
ps[q_grid <= q],
499
500
label='producer surplus',
500
- color='#E6E6F5')
501
+ color="green",
502
+ alpha=0.5)
501
503
ax.vlines(q, 0, p, linestyle="dashed", color='black', alpha=0.7)
502
504
ax.hlines(p, 0, q, linestyle="dashed", color='black', alpha=0.7)
503
505
@@ -538,7 +540,7 @@ producers pay the same price:
538
540
539
541
$$
540
542
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
542
544
$$
543
545
544
546
Evaluating the integrals gives
@@ -565,7 +567,7 @@ The next figure plots welfare as a function of $q$.
565
567
566
568
q_vals = np.linspace(0, 1.78, 200)
567
569
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' )
569
571
ax.legend(frameon=False)
570
572
ax.set_xlabel('quantity')
571
573
plt.show()
@@ -577,7 +579,7 @@ To compute a quantity that maximizes the welfare criterion, we differentiate
577
579
$W$ with respect to $q$ and then set the derivative to zero.
578
580
579
581
$$
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
581
583
$$
582
584
583
585
Solving for $q$ yields
@@ -704,8 +706,8 @@ supply_curve = market.inverse_supply(q_grid)
704
706
demand_curve = market.inverse_demand(q_grid)
705
707
706
708
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' )
709
711
ax.legend(loc='upper center', frameon=False)
710
712
ax.set_ylim(0, 1.2)
711
713
ax.set_xticks((0, 1))
@@ -736,7 +738,7 @@ supply curve:
736
738
737
739
$$
738
740
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
740
742
$$
741
743
742
744
Here $p$ is set to $i_s(q)$.
@@ -746,7 +748,7 @@ assumption that the price is the same for buyers and sellers:
746
748
747
749
$$
748
750
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
750
752
$$
751
753
752
754
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$.
786
788
787
789
```{code-cell} ipython3
788
790
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' )
790
792
ax.legend(frameon=False)
791
793
ax.set_xlabel('quantity')
792
794
plt.show()
0 commit comments