Created
January 4, 2021 13:13
-
-
Save FelixWeichselgartner/af60d274aafcc9434440820ae8539122 to your computer and use it in GitHub Desktop.
Python script to approximate the golden ratio with the fibonacci series
This file contains 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
import matplotlib.pyplot as plt | |
import numpy as np | |
from decimal import * | |
getcontext().prec = 20 | |
MAX_ITERATIONS = 20 | |
phi_approximations = list() | |
current_fib = Decimal(1) | |
last_fib = Decimal(1) | |
for i in range(MAX_ITERATIONS): | |
phi_approximations.append(current_fib / last_fib) | |
next_fib = current_fib + last_fib | |
last_fib = current_fib | |
current_fib = next_fib | |
for i in range(MAX_ITERATIONS): | |
print(f"{i}: \t{phi_approximations[i]}") | |
fig = plt.plot(range(MAX_ITERATIONS), phi_approximations) | |
plt.xlabel('Anzahl der Iterationen') | |
plt.ylabel('Wert') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment