@@ -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
@@ -614,7 +614,7 @@ tolerance bounds), we stop.
614614def bisection(pp, c0, k0, T=10, tol=1e-4, max_iter=500, k_ter=0, verbose=True):
615615
616616 # initial boundaries for guess c0
617- c0_upper = pp.f(k0)
617+ c0_upper = pp.f(k0) + (1 - pp.δ) * k0
618618 c0_lower = 0
619619
620620 i = 0
@@ -648,7 +648,7 @@ def plot_paths(pp, c0, k0, T_arr, k_ter=0, k_ss=None, axs=None):
648648
649649 if axs is None:
650650 fix, axs = plt.subplots(1, 3, figsize=(16, 4))
651- ylabels = ['$c_t$', '$k_t$', '$\mu_t$']
651+ ylabels = ['$c_t$', '$k_t$', r '$\mu_t$']
652652 titles = ['Consumption', 'Capital', 'Lagrange Multiplier']
653653
654654 c_paths = []
@@ -801,6 +801,77 @@ A rule of thumb for the planner is
801801The planner accomplishes this by adjusting the saving rate $\frac{f(K_t) - C_t}{f(K_t)}$
802802over time.
803803
804+ ```{exercise}
805+ :label: ck1_ex1
806+
807+ Turnspike property is an property that is independent of the
808+ initial condition $K_0$ as long as $T$ is large enough.
809+
810+ Try to expand the function `plot_paths` to plot paths
811+ of multiple initial points.
812+ ```
813+
814+ ```{solution-start} ck1_ex1
815+ :class: dropdown
816+ ```
817+
818+ Here is one solution
819+
820+ ```{code-cell} ipython3
821+ def plot_multiple_paths(pp, c0, k0s, T_arr, k_ter=0, k_ss=None, axs=None):
822+ if axs is None:
823+ fig, axs = plt.subplots(1, 3, figsize=(16, 4))
824+
825+ ylabels = ['$c_t$', '$k_t$', r'$\mu_t$']
826+ titles = ['Consumption', 'Capital', 'Lagrange Multiplier']
827+
828+ colors = plt.cm.viridis(np.linspace(0, 1, len(k0s)))
829+
830+ all_c_paths = []
831+ all_k_paths = []
832+
833+ for i, k0 in enumerate(k0s):
834+ k0_c_paths = []
835+ k0_k_paths = []
836+
837+ for T in T_arr:
838+ c_vec, k_vec = bisection(pp, c0, k0, T, k_ter=k_ter, verbose=False)
839+ k0_c_paths.append(c_vec)
840+ k0_k_paths.append(k_vec)
841+
842+ μ_vec = pp.u_prime(c_vec)
843+ paths = [c_vec, k_vec, μ_vec]
844+
845+ for j in range(3):
846+ axs[j].plot(paths[j], color=colors[i],
847+ label=f'$k_0 = {k0:.2f}$' if j == 0 and T == T_arr[0] else "", alpha=0.7)
848+ axs[j].set(xlabel='t', ylabel=ylabels[j], title=titles[j])
849+
850+ if k_ss is not None and i == 0 and T == T_arr[0]:
851+ axs[1].axhline(k_ss, c='k', ls='--', lw=1)
852+
853+ axs[1].axvline(T+1, c='k', ls='--', lw=1)
854+ axs[1].scatter(T+1, paths[1][-1], s=80, color=colors[i])
855+
856+ all_c_paths.append(k0_c_paths)
857+ all_k_paths.append(k0_k_paths)
858+
859+ # Add legend if multiple initial points
860+ if len(k0s) > 1:
861+ axs[0].legend()
862+
863+ return all_c_paths, all_k_paths
864+ ```
865+
866+ ```{code-cell} ipython3
867+ _ = plot_multiple_paths(pp, 0.3, [k_ss*2, k_ss*3, k_ss/3], [250, 150, 75, 50], k_ss=k_ss)
868+ ```
869+
870+ We can see that the turnpike property holds for different initial capital stocks $K_0$.
871+
872+ ```{solution-end}
873+ ```
874+
804875Let's calculate and plot the saving rate.
805876
806877```{code-cell} ipython3
@@ -1075,15 +1146,15 @@ studied in {doc}`Cass-Koopmans Competitive Equilibrium <cass_koopmans_2>` is a f
10751146### Exercise
10761147
10771148```{exercise}
1078- :label: ck1_ex1
1149+ :label: ck1_ex2
10791150
10801151- Plot the optimal consumption, capital, and saving paths when the
10811152 initial capital level begins at 1.5 times the steady state level
10821153 as we shoot towards the steady state at $T=130$.
10831154- Why does the saving rate respond as it does?
10841155```
10851156
1086- ```{solution-start} ck1_ex1
1157+ ```{solution-start} ck1_ex2
10871158:class: dropdown
10881159```
10891160
0 commit comments