@@ -100,6 +100,12 @@ The total height of each bar $i$ is willingness to pay by consumer $i$.
100
100
The orange portion of some of the bars shows consumer surplus.
101
101
102
102
``` {code-cell} ipython3
103
+ ---
104
+ mystnb:
105
+ figure:
106
+ caption: "Willingness to pay (discrete)"
107
+ name: wpdisc
108
+ ---
103
109
fig, ax = plt.subplots()
104
110
consumers = range(1, 11) # consumers 1,..., 10
105
111
# willingness to pay for each consumer
@@ -154,6 +160,12 @@ p = 100 e^{-q}
154
160
$$
155
161
156
162
``` {code-cell} ipython3
163
+ ---
164
+ mystnb:
165
+ figure:
166
+ caption: "Willingness to pay (continuous)"
167
+ name: wpcont
168
+ ---
157
169
def inverse_demand(q):
158
170
return 100 * np.exp(- q)
159
171
@@ -179,6 +191,12 @@ Reasoning by analogy with the discrete case, the area under the demand curve and
179
191
The consumer surplus is shaded in the figure below.
180
192
181
193
``` {code-cell} ipython3
194
+ ---
195
+ mystnb:
196
+ figure:
197
+ caption: "Willingness to pay (continuous) with consumer surplus"
198
+ name: wpcont_cs
199
+ ---
182
200
# solve for the value of q where demand meets price
183
201
q_star = np.log(100) - np.log(price)
184
202
@@ -211,12 +229,18 @@ Having discussed demand, let's now switch over to the supply side of the market.
211
229
The figure below shows the price at which a collection of producers, also numbered 1 to 10, are willing to sell one unit of the good in question
212
230
213
231
``` {code-cell} ipython3
232
+ ---
233
+ mystnb:
234
+ figure:
235
+ caption: "Willingness to sell (discrete)"
236
+ name: wsdisc
237
+ ---
214
238
fig, ax = plt.subplots()
215
239
producers = range(1, 11) # producers 1,..., 10
216
240
# willingness to sell for each producer
217
241
wts = (5, 8, 17, 22, 35, 39, 46, 57, 88, 91)
218
242
price = 25
219
- ax.bar(producers, wts, label="willingness to sell", color="blue ", alpha=0.8 )
243
+ ax.bar(producers, wts, label="willingness to sell", color="green ", alpha=0.5 )
220
244
ax.set_xlim(0, 12)
221
245
ax.set_xticks(producers)
222
246
ax.set_ylabel("willingness to sell")
251
275
The shaded area is the total producer surplus in this continuous model.
252
276
253
277
``` {code-cell} ipython3
278
+ ---
279
+ mystnb:
280
+ figure:
281
+ caption: "Willingness to sell (continuous) with producer surplus"
282
+ name: wscont
283
+ ---
254
284
def inverse_supply(q):
255
285
return 2 * q**2
256
286
@@ -293,6 +323,12 @@ In general, for a function $f$, the **integral** of $f$ over the interval $[a, b
293
323
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$.
294
324
295
325
``` {code-cell} ipython3
326
+ ---
327
+ mystnb:
328
+ figure:
329
+ caption: "Area under the curve"
330
+ name: integrate
331
+ ---
296
332
def f(x):
297
333
return np.cos(x/2) + 1
298
334
@@ -304,8 +340,7 @@ ab_grid = np.linspace(a, b, 400)
304
340
fig, ax = plt.subplots()
305
341
ax.plot(x_grid, f(x_grid), label="$f$", color="k")
306
342
ax.fill_between(ab_grid, [0] * len(ab_grid), f(ab_grid),
307
- label="$\int_a^b f(x) dx$",
308
- color='grey', alpha=0.5)
343
+ label="$\int_a^b f(x) dx$")
309
344
ax.legend()
310
345
plt.show()
311
346
```
@@ -388,6 +423,12 @@ def inverse_supply(q, model):
388
423
Here is a plot of these two functions using ` market ` .
389
424
390
425
``` {code-cell} ipython3
426
+ ---
427
+ mystnb:
428
+ figure:
429
+ caption: "Supply and demand"
430
+ name: supply_demand
431
+ ---
391
432
market = create_market()
392
433
393
434
grid_min, grid_max, grid_size = 0, 1.5, 200
@@ -425,6 +466,12 @@ $$ (eq:cstm_spls)
425
466
The next figure illustrates
426
467
427
468
```{code-cell} ipython3
469
+ ---
470
+ mystnb:
471
+ figure:
472
+ caption: "Supply and demand (consumer surplus)"
473
+ name: supply_demand_cs
474
+ ---
428
475
:tags: [hide-input]
429
476
430
477
q = 1.25
@@ -485,6 +532,12 @@ $$ (eq:pdcr_spls)
485
532
The next figure illustrates
486
533
487
534
```{code-cell} ipython3
535
+ ---
536
+ mystnb:
537
+ figure:
538
+ caption: "Supply and demand (producer surplus)"
539
+ name: supply_demand_ps
540
+ ---
488
541
:tags: [hide-input]
489
542
490
543
q = 0.75
@@ -560,6 +613,12 @@ def W(q, market):
560
613
The next figure plots welfare as a function of $q$.
561
614
562
615
```{code-cell} ipython3
616
+ ---
617
+ mystnb:
618
+ figure:
619
+ caption: "Welfare"
620
+ name: wf
621
+ ---
563
622
:tags: [hide-input]
564
623
565
624
q_vals = np.linspace(0, 1.78, 200)
0 commit comments