Skip to content

Commit 4cdc4df

Browse files
authored
Fibonacci: better motivation for matrix form
1 parent 91672f0 commit 4cdc4df

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/algebra/fibonacci-numbers.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,48 @@ In this way, we obtain a linear solution, $O(n)$ time, saving all the values pri
116116
117117
### Matrix form
118118
119-
It is easy to prove the following relation:
119+
To go from $(F_n, F_{n-1})$ to $(F_{n+1}, F_n)$, we can express the linear recurrence as a 2x2 matrix multiplication:
120120
121-
$$\begin{pmatrix} 1 & 1 \cr 1 & 0 \cr\end{pmatrix} ^ n = \begin{pmatrix} F_{n+1} & F_{n} \cr F_{n} & F_{n-1} \cr\end{pmatrix}$$
121+
$$
122+
\begin{pmatrix}
123+
1 & 1 \\
124+
1 & 0
125+
\end{pmatrix}
126+
\begin{pmatrix}
127+
F_n \\
128+
F_{n-1}
129+
\end{pmatrix}
130+
=
131+
\begin{pmatrix}
132+
F_n + F_{n-1} \\
133+
F_{n}
134+
\end{pmatrix}
135+
=
136+
\begin{pmatrix}
137+
F_{n+1} \\
138+
F_{n}
139+
\end{pmatrix}
140+
$$
141+
142+
This lets us treat iterating the recurrence as repeated matrix multiplication, which has nice properties. In particular,
143+
144+
$$
145+
\begin{pmatrix}
146+
1 & 1 \\
147+
1 & 0
148+
\end{pmatrix}^n
149+
\begin{pmatrix}
150+
F_1 \\
151+
F_0
152+
\end{pmatrix}
153+
=
154+
\begin{pmatrix}
155+
F_{n+1} \\
156+
F_{n}
157+
\end{pmatrix}
158+
$$
159+
160+
where $F_1 = 1, F_0 = 0$.
122161
123162
Thus, in order to find $F_n$ in $O(log n)$ time, we must raise the matrix to n. (See [Binary exponentiation](binary-exp.md))
124163

0 commit comments

Comments
 (0)