In [ ]:
F0 = 0
F1 = 1
N = 20 # How many numbers to generate
In [ ]:
print(F0)
a, b = F0, F1
for _ in range(N):
a, b = b, a + b
print(a)
Dividing consecutive Fibonacci numbers gives numbers which get closer to the golden ratio.
In [ ]:
ratios = []
a, b = F0, F1
for _ in range(N):
a, b = b, a + b
ratios.append(b / a)
In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
In [ ]:
from math import sqrt
plt.plot(ratios)
Φ = (1 + sqrt(5)) / 2 # The golden ratio
plt.hlines(Φ, xmin=0, xmax=N, linestyles='dotted')