@@ -4,7 +4,7 @@ jupytext:
44 extension : .md
55 format_name : myst
66 format_version : 0.13
7- jupytext_version : 1.16.4
7+ jupytext_version : 1.17.2
88kernelspec :
99 display_name : Python 3 (ipykernel)
1010 language : python
@@ -62,6 +62,13 @@ The lecture uses important ideas including
6262 long but finite-horizon economies.
6363- A ** stable manifold** and a ** phase plane**
6464
65+ In addition to what's in Anaconda, this lecture will need the following libraries:
66+
67+ ``` {code-cell} ipython
68+ :tags: [hide-output]
69+ !pip install quantecon
70+ ```
71+
6572Let's start with some standard imports:
6673
6774``` {code-cell} ipython3
@@ -614,7 +621,7 @@ tolerance bounds), we stop.
614621def bisection(pp, c0, k0, T=10, tol=1e-4, max_iter=500, k_ter=0, verbose=True):
615622
616623 # initial boundaries for guess c0
617- c0_upper = pp.f(k0)
624+ c0_upper = pp.f(k0) + (1 - pp.δ) * k0
618625 c0_lower = 0
619626
620627 i = 0
@@ -648,7 +655,7 @@ def plot_paths(pp, c0, k0, T_arr, k_ter=0, k_ss=None, axs=None):
648655
649656 if axs is None:
650657 fix, axs = plt.subplots(1, 3, figsize=(16, 4))
651- ylabels = ['$c_t$', '$k_t$', '$\mu_t$']
658+ ylabels = ['$c_t$', '$k_t$', r '$\mu_t$']
652659 titles = ['Consumption', 'Capital', 'Lagrange Multiplier']
653660
654661 c_paths = []
@@ -801,6 +808,76 @@ A rule of thumb for the planner is
801808The planner accomplishes this by adjusting the saving rate $\frac{f(K_t) - C_t}{f(K_t)}$
802809over time.
803810
811+ ```{exercise}
812+ :label: ck1_ex1
813+
814+ The turnpike property is independent of the initial condition
815+ $K_0$ provided that $T$ is sufficiently large.
816+
817+ Expand the `plot_paths` function so that it plots trajectories for multiple initial points using `k0s = [k_ss*2, k_ss*3, k_ss/3]`.
818+ ```
819+
820+ ```{solution-start} ck1_ex1
821+ :class: dropdown
822+ ```
823+
824+ Here is one solution
825+
826+ ```{code-cell} ipython3
827+ def plot_multiple_paths(pp, c0, k0s, T_arr, k_ter=0, k_ss=None, axs=None):
828+ if axs is None:
829+ fig, axs = plt.subplots(1, 3, figsize=(16, 4))
830+
831+ ylabels = ['$c_t$', '$k_t$', r'$\mu_t$']
832+ titles = ['Consumption', 'Capital', 'Lagrange Multiplier']
833+
834+ colors = plt.cm.viridis(np.linspace(0, 1, len(k0s)))
835+
836+ all_c_paths = []
837+ all_k_paths = []
838+
839+ for i, k0 in enumerate(k0s):
840+ k0_c_paths = []
841+ k0_k_paths = []
842+
843+ for T in T_arr:
844+ c_vec, k_vec = bisection(pp, c0, k0, T, k_ter=k_ter, verbose=False)
845+ k0_c_paths.append(c_vec)
846+ k0_k_paths.append(k_vec)
847+
848+ μ_vec = pp.u_prime(c_vec)
849+ paths = [c_vec, k_vec, μ_vec]
850+
851+ for j in range(3):
852+ axs[j].plot(paths[j], color=colors[i],
853+ label=f'$k_0 = {k0:.2f}$' if j == 0 and T == T_arr[0] else "", alpha=0.7)
854+ axs[j].set(xlabel='t', ylabel=ylabels[j], title=titles[j])
855+
856+ if k_ss is not None and i == 0 and T == T_arr[0]:
857+ axs[1].axhline(k_ss, c='k', ls='--', lw=1)
858+
859+ axs[1].axvline(T+1, c='k', ls='--', lw=1)
860+ axs[1].scatter(T+1, paths[1][-1], s=80, color=colors[i])
861+
862+ all_c_paths.append(k0_c_paths)
863+ all_k_paths.append(k0_k_paths)
864+
865+ # Add legend if multiple initial points
866+ if len(k0s) > 1:
867+ axs[0].legend()
868+
869+ return all_c_paths, all_k_paths
870+ ```
871+
872+ ```{code-cell} ipython3
873+ _ = plot_multiple_paths(pp, 0.3, [k_ss*2, k_ss*3, k_ss/3], [250, 150, 75, 50], k_ss=k_ss)
874+ ```
875+
876+ We see that the turnpike property holds for various initial values of $K_0$.
877+
878+ ```{solution-end}
879+ ```
880+
804881Let's calculate and plot the saving rate.
805882
806883```{code-cell} ipython3
@@ -1075,15 +1152,15 @@ studied in {doc}`Cass-Koopmans Competitive Equilibrium <cass_koopmans_2>` is a f
10751152### Exercise
10761153
10771154```{exercise}
1078- :label: ck1_ex1
1155+ :label: ck1_ex2
10791156
10801157- Plot the optimal consumption, capital, and saving paths when the
10811158 initial capital level begins at 1.5 times the steady state level
10821159 as we shoot towards the steady state at $T=130$.
10831160- Why does the saving rate respond as it does?
10841161```
10851162
1086- ```{solution-start} ck1_ex1
1163+ ```{solution-start} ck1_ex2
10871164:class: dropdown
10881165```
10891166
0 commit comments