Created
November 14, 2021 08:32
-
-
Save nschloe/ab6c3c90b4a6bc02c40405803fa8fa35 to your computer and use it in GitHub Desktop.
Golden ratio vs. Fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
fibonacci = [1, 1] | |
phi = (sqrt(5) - 1) / 2 | |
print(phi) | |
print() | |
errors = [] | |
n = 40 | |
for _ in range(n): | |
approx = fibonacci[0] / fibonacci[1] | |
errors.append(abs(phi - approx)) | |
print(fibonacci, errors[-1]) | |
s = fibonacci[0] + fibonacci[1] | |
fibonacci[0] = fibonacci[1] | |
fibonacci[1] = s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error decreases linearly: