Skip to content

Commit d255488

Browse files
committed
update visualization and add full stops for some sentences\
1 parent 38e6ed3 commit d255488

File tree

1 file changed

+47
-56
lines changed

1 file changed

+47
-56
lines changed

lectures/greek_square.md

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@ kernelspec:
1717
## Introduction
1818

1919

20-
This lecture can be viewed as a sequel to {doc}`eigen_I`
20+
This lecture can be viewed as a sequel to {doc}`eigen_I`.
2121

2222
It provides an example of how eigenvectors isolate *invariant subspaces* that help construct and analyze solutions of linear difference equations.
2323

2424
When vector $x_t$ starts in an invariant subspace, iterating the different equation keeps $x_{t+j}$
2525
in that subspace for all $j \geq 1$.
2626

27-
Invariant subspace methods are used throughout applied economic dynamics, for example, in the lecture {doc}`money_inflation`
27+
Invariant subspace methods are used throughout applied economic dynamics, for example, in the lecture {doc}`money_inflation`.
2828

2929
Our approach here is to illustrate the method with an ancient example, one that ancient Greek mathematicians used to compute square roots of positive integers.
3030

31-
In this lecture we assume that we have yet
32-
3331
## Perfect squares and irrational numbers
3432

3533
An integer is called a **perfect square** if its square root is also an integer.
@@ -46,11 +44,11 @@ The ancient Greeks invented an algorithm to compute square roots of integers, in
4644

4745
Their method involved
4846

49-
* computing a particular sequence of integers $\{y_t\}_{t=0}^\infty$
47+
* computing a particular sequence of integers $\{y_t\}_{t=0}^\infty$;
5048

51-
* computing $\lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = \bar r$
49+
* computing $\lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = \bar r$;
5250

53-
* deducing the desired square root from $\bar r$
51+
* deducing the desired square root from $\bar r$.
5452

5553
In this lecture, we'll describe this method.
5654

@@ -90,7 +88,7 @@ equation {eq}`eq:2diff1` for each $t \geq 0$.
9088
We seek an expression for $y_t, t \geq 0$ as functions of the initial conditions $(y_{-1}, y_{-2})$:
9189
9290
$$
93-
y_t = g((y_{-1}, y_{-2});t), \quad t \geq 0
91+
y_t = g((y_{-1}, y_{-2});t), \quad t \geq 0.
9492
$$ (eq:2diff2)
9593
9694
We call such a function $g$ a *solution* of the difference equation {eq}`eq:2diff1`.
@@ -110,7 +108,7 @@ For initial condition that satisfy {eq}`eq:2diff3`
110108
equation {eq}`eq:2diff1` impllies that
111109
112110
$$
113-
y_0 = \left(a_1 + \frac{a_2}{\delta}\right) y_{-1}
111+
y_0 = \left(a_1 + \frac{a_2}{\delta}\right) y_{-1}.
114112
$$ (eq:2diff4)
115113
116114
We want
@@ -122,13 +120,13 @@ $$ (eq:2diff5)
122120
which we can rewrite as the *characteristic equation*
123121
124122
$$
125-
\delta^2 - a_1 \delta - a_2 = 0
123+
\delta^2 - a_1 \delta - a_2 = 0.
126124
$$ (eq:2diff6)
127125
128126
Applying the quadratic formula to solve for the roots of {eq}`eq:2diff6` we find that
129127
130128
$$
131-
\delta = \frac{ a_1 \pm \sqrt{a_1^2 + 4 a_2}}{2}
129+
\delta = \frac{ a_1 \pm \sqrt{a_1^2 + 4 a_2}}{2}.
132130
$$ (eq:2diff7)
133131
134132
For either of the two $\delta$'s that satisfy equation {eq}`eq:2diff7`,
@@ -177,9 +175,9 @@ We'll turn to that after we describe how Ancient Greeks figured out how to compu
177175
178176
## Algorithm of the Ancient Greeks
179177
180-
Let $\sigma$ be a positive integer greater than $1$
178+
Let $\sigma$ be a positive integer greater than $1$.
181179
182-
So $\sigma \in {\mathcal I} \equiv \{2, 3, \ldots \}$
180+
So $\sigma \in {\mathcal I} \equiv \{2, 3, \ldots \}$.
183181
184182
We want an algorithm to compute the square root of $\sigma \in {\mathcal I}$.
185183
@@ -195,20 +193,16 @@ $$
195193
y_{t} = 2 y_{t-1} - (1 - \sigma) y_{t-2}, \quad t \geq 0
196194
$$ (eq:second_order)
197195
198-
together with a pair of integers that are initial conditions for $y_{-1}, y_{-2}$.
199-
200-
First, we'll deploy some techniques for solving the difference equations that are also deployed in {doc}`dynam:samuelson`
201-
196+
together with a pair of integers that are initial conditions for $y_{-1}, y_{-2}$.
202197
198+
First, we'll deploy some techniques for solving the difference equations that are also deployed in {doc}`dynam:samuelson`.
203199
204200
The characteristic equation associated with difference equation {eq}`eq:second_order` is
205201
206202
$$
207203
c(x) \equiv x^2 - 2 x + (1 - \sigma) = 0
208204
$$ (eq:cha_eq0)
209205
210-
211-
212206
(Notice how this is an instance of equation {eq}`eq:2diff6` above.)
213207
214208
Factoring the right side of equation {eq}`eq:cha_eq0`, we obtain
@@ -233,11 +227,11 @@ By applying the quadratic formula to solve for the roots the characteristic equ
233227
{eq}`eq:cha_eq0`, we find that
234228
235229
$$
236-
\lambda_1 = 1 + \sqrt{\sigma}, \quad \lambda_2 = 1 - \sqrt{\sigma}
230+
\lambda_1 = 1 + \sqrt{\sigma}, \quad \lambda_2 = 1 - \sqrt{\sigma}.
237231
$$ (eq:secretweapon)
238232
239233
Formulas {eq}`eq:secretweapon` indicate that $\lambda_1$ and $\lambda_2$ are each functions
240-
of a single variable, namely, $\sqrt{\sigma}$, the object that we along with some Ancient Greeks want to compute.
234+
of a single variable, namely, $\sqrt{\sigma}$, the object that we along with some Ancient Greeks want to compute.
241235
242236
Ancient Greeks had an indirect way of exploiting this fact to compute square roots of a positive integer.
243237
@@ -265,13 +259,13 @@ Since $\lambda_1 = 1 + \sqrt{\sigma} > 1 > \lambda_2 = 1 - \sqrt{\sigma} $,
265259
it follows that for *almost all* (but not all) initial conditions
266260
267261
$$
268-
\lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = 1 + \sqrt{\sigma}
262+
\lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) = 1 + \sqrt{\sigma}.
269263
$$
270264
271265
Thus,
272266
273267
$$
274-
\sqrt{\sigma} = \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) - 1
268+
\sqrt{\sigma} = \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right) - 1.
275269
$$
276270
277271
However, notice that if $\eta_1 = 0$, then
@@ -283,7 +277,7 @@ $$
283277
so that
284278
285279
$$
286-
\sqrt{\sigma} = 1 - \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right)
280+
\sqrt{\sigma} = 1 - \lim_{t \rightarrow \infty} \left(\frac{y_{t+1}}{y_t}\right).
287281
$$
288282
289283
Actually, if $\eta_1 =0$, it follows that
@@ -306,9 +300,9 @@ so again, convergence is immediate, and we have no need to compute a limit.
306300
307301
System {eq}`eq:leq_sq` of simultaneous linear equations can be used in various ways.
308302
309-
* we can take $y_{-1}, y_{-2}$ as given initial conditions and solve for $\eta_1, \eta_2$
303+
* we can take $y_{-1}, y_{-2}$ as given initial conditions and solve for $\eta_1, \eta_2$;
310304
311-
* we can instead take $\eta_1, \eta_2$ as given and solve for initial conditions $y_{-1}, y_{-2}$
305+
* we can instead take $\eta_1, \eta_2$ as given and solve for initial conditions $y_{-1}, y_{-2}$.
312306
313307
Notice how we used the second approach above when we set $\eta_1, \eta_2$ either to $(0, 1)$, for example, or $(1, 0)$, for example.
314308
@@ -330,7 +324,6 @@ But first let's write some Python code to iterate on equation {eq}`eq:second_ord
330324
331325
We now implement the above algorithm to compute the square root of $\sigma$.
332326
333-
334327
In this lecture, we use the following import:
335328
336329
```{code-cell} ipython3
@@ -594,16 +587,14 @@ $$
594587
595588
that
596589
597-
598-
599590
$$
600591
V^{2,1} V_{1,1} + V^{2,2} V_{2,1} = 0
601592
$$
602593
603594
and
604595
605596
$$
606-
V^{1,1}V_{1,2} + V^{1,2} V_{2,2} = 0
597+
V^{1,1}V_{1,2} + V^{1,2} V_{2,2} = 0.
607598
$$
608599
609600
These equations will be very useful soon.
@@ -619,7 +610,7 @@ $$
619610
To deactivate $\lambda_1$ we want to set
620611
621612
$$
622-
x_{1,0}^* = 0
613+
x_{1,0}^* = 0.
623614
$$
624615
625616
@@ -638,7 +629,7 @@ $$
638629
This can be achieved by setting
639630
640631
$$
641-
x_{2,0} = -(V^{2,2})^{-1} V^{2,1} x_{1,0} = V_{2,1} V_{1,1}^{-1} x_{1,0}
632+
x_{2,0} = -(V^{2,2})^{-1} V^{2,1} x_{1,0} = V_{2,1} V_{1,1}^{-1} x_{1,0}.
642633
$$ (eq:deactivate2)
643634
644635
Let's verify {eq}`eq:deactivate1` and {eq}`eq:deactivate2` below
@@ -687,30 +678,30 @@ We find that the ratios converge to $\lambda_2$ in the first case and $\lambda_1
687678
```{code-cell} ipython3
688679
:tags: [hide-input]
689680
690-
# Plot the ratios for y_t
691-
plt.figure(figsize=(14, 6))
692-
693-
plt.subplot(1, 2, 1)
694-
plt.plot(np.round(ratios_λ1, 6),
695-
label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3)
696-
plt.axhline(y=Λ[1], color='red',
697-
linestyle='--', label='$\lambda_2$', alpha=0.5)
698-
plt.xlabel('t', size=18)
699-
plt.ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18)
700-
plt.title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_1$',
701-
size=13)
702-
plt.legend()
703-
704-
plt.subplot(1, 2, 2)
705-
plt.plot(ratios_λ2,
706-
label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3)
707-
plt.axhline(y=Λ[0], color='green',
708-
linestyle='--', label='$\lambda_1$', alpha=0.5)
709-
plt.xlabel('t', size=18)
710-
plt.ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18)
711-
plt.title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_2$',
712-
size=13)
713-
plt.legend()
681+
# Plot the ratios for y_t / y_{t-1}
682+
fig, axs = plt.subplots(1, 2, figsize=(14, 6))
683+
684+
# First subplot
685+
axs[0].plot(np.round(ratios_λ1, 6),
686+
label=r'$\frac{y_t}{y_{t-1}}$', linewidth=3)
687+
axs[0].axhline(y=Λ[1], color='red', linestyle='--',
688+
label='$\lambda_2$', alpha=0.5)
689+
axs[0].set_xlabel('t', size=18)
690+
axs[0].set_ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18)
691+
axs[0].set_title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_1$',
692+
size=13)
693+
axs[0].legend()
694+
695+
# Second subplot
696+
axs[1].plot(ratios_λ2, label=r'$\frac{y_t}{y_{t-1}}$',
697+
linewidth=3)
698+
axs[1].axhline(y=Λ[0], color='green', linestyle='--',
699+
label='$\lambda_1$', alpha=0.5)
700+
axs[1].set_xlabel('t', size=18)
701+
axs[1].set_ylabel(r'$\frac{y_t}{y_{t-1}}$', size=18)
702+
axs[1].set_title(r'$\frac{y_t}{y_{t-1}}$ after Muting $\lambda_2$',
703+
size=13)
704+
axs[1].legend()
714705
715706
plt.tight_layout()
716707
plt.show()

0 commit comments

Comments
 (0)