@@ -98,119 +98,6 @@ def creat_cs_model(R=1.05, g1=1, g2=1/2, T=65):
98
98
99
99
+++ {"user_expressions": []}
100
100
101
- ## Difference equations with linear algebra
102
-
103
- As a warmup, we'll describe a useful way of representing and "solving" linear difference equations.
104
-
105
- To generate some $y$ vectors, we'll just write down a linear difference equation
106
- with appropriate initial conditions and then use linear algebra to solve it.
107
-
108
- ### First-order difference equation
109
-
110
- We'll start with a first-order linear difference equation for $\{y_t\}_{t=0}^T$:
111
-
112
- $$
113
- y_ {t} = \lambda y_ {t-1}, \quad t = 1, 2, \ldots, T
114
- $$
115
-
116
- where $y_0$ is a given initial condition.
117
-
118
-
119
- We can cast this set of $T$ equations as a single matrix equation
120
-
121
- $$
122
- \begin{bmatrix}
123
- 1 & 0 & 0 & \cdots & 0 & 0 \cr
124
- -\lambda & 1 & 0 & \cdots & 0 & 0 \cr
125
- 0 & -\lambda & 1 & \cdots & 0 & 0 \cr
126
- \vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
127
- 0 & 0 & 0 & \cdots & -\lambda & 1
128
- \end{bmatrix}
129
- \begin{bmatrix}
130
- y_1 \cr y_2 \cr y_3 \cr \vdots \cr y_T
131
- \end{bmatrix}
132
- =
133
- \begin{bmatrix}
134
- \lambda y_0 \cr 0 \cr 0 \cr \vdots \cr 0
135
- \end{bmatrix}
136
- $$
137
-
138
-
139
- Multiplying both sides by inverse of the matrix on the left provides the solution
140
-
141
- ```{math}
142
- :label: fst_ord_inverse
143
-
144
- \begin{bmatrix}
145
- y_1 \cr y_2 \cr y_3 \cr \vdots \cr y_T
146
- \end{bmatrix}
147
- =
148
- \begin{bmatrix}
149
- 1 & 0 & 0 & \cdots & 0 & 0 \cr
150
- \lambda & 1 & 0 & \cdots & 0 & 0 \cr
151
- \lambda^2 & \lambda & 1 & \cdots & 0 & 0 \cr
152
- \vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
153
- \lambda^{T-1} & \lambda^{T-2} & \lambda^{T-3} & \cdots & \lambda & 1
154
- \end{bmatrix}
155
- \begin{bmatrix}
156
- \lambda y_0 \cr 0 \cr 0 \cr \vdots \cr 0
157
- \end{bmatrix}
158
- ```
159
-
160
- ```{exercise}
161
- :label: consmooth_ex1
162
-
163
- In the {eq}`fst_ord_inverse`, we multiply the inverse of the matrix $A$. In this exercise, please confirm that
164
-
165
- $$
166
- \begin{bmatrix}
167
- 1 & 0 & 0 & \cdots & 0 & 0 \cr
168
- \lambda & 1 & 0 & \cdots & 0 & 0 \cr
169
- \lambda^2 & \lambda & 1 & \cdots & 0 & 0 \cr
170
- \vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
171
- \lambda^{T-1} & \lambda^{T-2} & \lambda^{T-3} & \cdots & \lambda & 1
172
- \end{bmatrix}
173
- $$
174
-
175
- is the inverse of $A$ and check that $A A^{-1} = I$
176
-
177
- ```
178
-
179
- ### Second order difference equation
180
-
181
- The second-order linear difference equation for $\{y_t\}_{t=0}^T$ is
182
-
183
- $$
184
- y_ {t} = \lambda_1 y_ {t-1} + \lambda_2 y_ {t-2}, \quad t = 1, 2, \ldots, T
185
- $$
186
-
187
- Similarly, we can cast this set of $T$ equations as a single matrix equation
188
-
189
- $$
190
- \begin{bmatrix}
191
- 1 & 0 & 0 & \cdots & 0 & 0 & 0 \cr
192
- -\lambda_1 & 1 & 0 & \cdots & 0 & 0 & 0 \cr
193
- -\lambda_2 & -\lambda_1 & 1 & \cdots & 0 & 0 & 0 \cr
194
- \vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
195
- 0 & 0 & 0 & \cdots & -\lambda_2 & -\lambda_1 & 1
196
- \end{bmatrix}
197
- \begin{bmatrix}
198
- y_1 \cr y_2 \cr y_3 \cr \vdots \cr y_T
199
- \end{bmatrix}
200
- =
201
- \begin{bmatrix}
202
- \lambda_1 y_0 + \lambda_2 y_ {-1} \cr \lambda_2 y_0 \cr 0 \cr \vdots \cr 0
203
- \end{bmatrix}
204
- $$
205
-
206
- Multiplying both sides by inverse of the matrix on the left again provides the solution.
207
-
208
- ```{exercise}
209
- :label: consmooth_ex2
210
-
211
- As an exercise, we ask you to represent and solve a **third order linear difference equation**.
212
- How many initial conditions must you specify?
213
- ```
214
101
215
102
## Friedman-Hall consumption-smoothing model
216
103
@@ -558,3 +445,124 @@ plt.ylabel('derivatives of welfare')
558
445
plt.xlabel(r'$\phi$')
559
446
plt.show()
560
447
```
448
+
449
+
450
+ ## Difference equations with linear algebra
451
+
452
+ In the preceding sections we have used linear algebra to solve a consumption smoothing model.
453
+
454
+ The same tools from linear algebra -- matrix multiplication and matrix inversion -- can be used to study many other dynamic models too.
455
+
456
+ We'll concluse this lecture by giving a couple of examples.
457
+
458
+ In particular, we'll describe a useful way of representing and "solving" linear difference equations.
459
+
460
+ To generate some $y$ vectors, we'll just write down a linear difference equation
461
+ with appropriate initial conditions and then use linear algebra to solve it.
462
+
463
+ ### First-order difference equation
464
+
465
+ We'll start with a first-order linear difference equation for $\{y_t\}_{t=0}^T$:
466
+
467
+ $$
468
+ y_ {t} = \lambda y_ {t-1}, \quad t = 1, 2, \ldots, T
469
+ $$
470
+
471
+ where $y_0$ is a given initial condition.
472
+
473
+
474
+ We can cast this set of $T$ equations as a single matrix equation
475
+
476
+ $$
477
+ \begin{bmatrix}
478
+ 1 & 0 & 0 & \cdots & 0 & 0 \cr
479
+ -\lambda & 1 & 0 & \cdots & 0 & 0 \cr
480
+ 0 & -\lambda & 1 & \cdots & 0 & 0 \cr
481
+ \vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
482
+ 0 & 0 & 0 & \cdots & -\lambda & 1
483
+ \end{bmatrix}
484
+ \begin{bmatrix}
485
+ y_1 \cr y_2 \cr y_3 \cr \vdots \cr y_T
486
+ \end{bmatrix}
487
+ =
488
+ \begin{bmatrix}
489
+ \lambda y_0 \cr 0 \cr 0 \cr \vdots \cr 0
490
+ \end{bmatrix}
491
+ $$
492
+
493
+
494
+ Multiplying both sides by inverse of the matrix on the left provides the solution
495
+
496
+ ```{math}
497
+ :label: fst_ord_inverse
498
+
499
+ \begin{bmatrix}
500
+ y_1 \cr y_2 \cr y_3 \cr \vdots \cr y_T
501
+ \end{bmatrix}
502
+ =
503
+ \begin{bmatrix}
504
+ 1 & 0 & 0 & \cdots & 0 & 0 \cr
505
+ \lambda & 1 & 0 & \cdots & 0 & 0 \cr
506
+ \lambda^2 & \lambda & 1 & \cdots & 0 & 0 \cr
507
+ \vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
508
+ \lambda^{T-1} & \lambda^{T-2} & \lambda^{T-3} & \cdots & \lambda & 1
509
+ \end{bmatrix}
510
+ \begin{bmatrix}
511
+ \lambda y_0 \cr 0 \cr 0 \cr \vdots \cr 0
512
+ \end{bmatrix}
513
+ ```
514
+
515
+ ```{exercise}
516
+ :label: consmooth_ex1
517
+
518
+ In the {eq}`fst_ord_inverse`, we multiply the inverse of the matrix $A$. In this exercise, please confirm that
519
+
520
+ $$
521
+ \begin{bmatrix}
522
+ 1 & 0 & 0 & \cdots & 0 & 0 \cr
523
+ \lambda & 1 & 0 & \cdots & 0 & 0 \cr
524
+ \lambda^2 & \lambda & 1 & \cdots & 0 & 0 \cr
525
+ \vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
526
+ \lambda^{T-1} & \lambda^{T-2} & \lambda^{T-3} & \cdots & \lambda & 1
527
+ \end{bmatrix}
528
+ $$
529
+
530
+ is the inverse of $A$ and check that $A A^{-1} = I$
531
+
532
+ ```
533
+
534
+ ### Second order difference equation
535
+
536
+ The second-order linear difference equation for $\{y_t\}_{t=0}^T$ is
537
+
538
+ $$
539
+ y_ {t} = \lambda_1 y_ {t-1} + \lambda_2 y_ {t-2}, \quad t = 1, 2, \ldots, T
540
+ $$
541
+
542
+ Similarly, we can cast this set of $T$ equations as a single matrix equation
543
+
544
+ $$
545
+ \begin{bmatrix}
546
+ 1 & 0 & 0 & \cdots & 0 & 0 & 0 \cr
547
+ -\lambda_1 & 1 & 0 & \cdots & 0 & 0 & 0 \cr
548
+ -\lambda_2 & -\lambda_1 & 1 & \cdots & 0 & 0 & 0 \cr
549
+ \vdots & \vdots & \vdots & \cdots & \vdots & \vdots \cr
550
+ 0 & 0 & 0 & \cdots & -\lambda_2 & -\lambda_1 & 1
551
+ \end{bmatrix}
552
+ \begin{bmatrix}
553
+ y_1 \cr y_2 \cr y_3 \cr \vdots \cr y_T
554
+ \end{bmatrix}
555
+ =
556
+ \begin{bmatrix}
557
+ \lambda_1 y_0 + \lambda_2 y_ {-1} \cr \lambda_2 y_0 \cr 0 \cr \vdots \cr 0
558
+ \end{bmatrix}
559
+ $$
560
+
561
+ Multiplying both sides by inverse of the matrix on the left again provides the solution.
562
+
563
+ ```{exercise}
564
+ :label: consmooth_ex2
565
+
566
+ As an exercise, we ask you to represent and solve a **third order linear difference equation**.
567
+ How many initial conditions must you specify?
568
+ ```
0 commit comments