Skip to content

Commit 0b2b4c4

Browse files
committed
update solution and quote directives
1 parent 8d020da commit 0b2b4c4

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

lectures/greek_square.md

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.16.2
7+
jupytext_version: 1.16.1
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -16,12 +16,10 @@ kernelspec:
1616

1717
## Introduction
1818

19-
20-
2119
Chapter 24 of {cite}`russell2004history` about early Greek mathematics and astronomy contains this
2220
fascinating passage:
2321

24-
```{note}
22+
```{epigraph}
2523
The square root of 2, which was the first irrational to be discovered, was known to the early Pythagoreans, and ingenious methods of approximating to its value were discovered. The best was as follows: Form two columns of numbers, which we will call the $a$'s and the $b$'s; each starts with a $1$. The next $a$, at each stage, is formed by adding the last $a$ and the $b$ already obtained; the next $b$ is formed by adding twice the previous $a$ to the previous $b$. The first 6 pairs so obtained are $(1,1), (2,3), (5,7), (12,17), (29,41), (70,99)$. In each pair, $2 a - b$ is $1$ or $-1$. Thus $b/a$ is nearly the square root of two, and at each fresh step it gets nearer. For instance, the reader may satisy himself that the square of $99/70$ is very nearly equal to $2$.
2624
```
2725

@@ -727,6 +725,7 @@ We shall encounter equations very similar to {eq}`eq:deactivate1` and {eq}`eq:de
727725
in {doc}`money_inflation` and in many other places in dynamic economic theory.
728726
729727
728+
## Exercise
730729
731730
```{exercise-start}
732731
:label: greek_square_ex_a
@@ -745,7 +744,56 @@ compute the matrix $A$.
745744
```{solution-start} greek_square_ex_a
746745
:class: dropdown
747746
```
748-
Here is the answer
747+
Here is one soluition.
748+
749+
According to the quote, we can formulate
750+
751+
$$
752+
\begin{aligned}
753+
a_{t+1} &= a_t + b_t \\
754+
b_{t+1} &= 2a_t + b_t
755+
\end{aligned}
756+
$$ (eq:gs_ex1system)
757+
758+
with $x_0 = \begin{bmatrix} a_0 \cr b_0 \end{bmatrix} = \begin{bmatrix} 1 \cr 1 \end{bmatrix}$
759+
760+
By {eq}`eq:gs_ex1system`, we can write matix $A$ as
761+
762+
$$
763+
A = \begin{bmatrix} 1 & 1 \cr
764+
2 & 1 \end{bmatrix}
765+
$$
766+
767+
Then $x_{t+1} = A x_t$ with $t \in \{0, \dots, 5\}$
768+
769+
```{code-cell} ipython3
770+
# Define the matrix A
771+
A = np.array([[1, 1],
772+
[2, 1]])
773+
774+
# Initial vector x_0
775+
x_0 = np.array([1, 1])
776+
777+
# Number of iterations
778+
n = 6
779+
780+
# Generate the sequence
781+
xs = np.array([x_0])
782+
x_t = x_0
783+
for _ in range(1, n):
784+
x_t = A @ x_t
785+
xs = np.vstack([xs, x_t])
786+
787+
# Print the sequence
788+
for i, (a_t, b_t) in enumerate(xs):
789+
print(f"Iter {i}: a_t = {a_t}, b_t = {b_t}")
790+
791+
# Compute eigenvalues and eigenvectors of A
792+
eigenvalues, eigenvectors = np.linalg.eig(A)
793+
794+
print(f'\nEigenvalues:\n{eigenvalues}')
795+
print(f'\nEigenvectors:\n{eigenvectors}')
796+
```
749797
750798
```{solution-end}
751-
```
799+
```

0 commit comments

Comments
 (0)