Skip to content

Instantly share code, notes, and snippets.

@FelixWeichselgartner
Created January 4, 2021 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FelixWeichselgartner/af60d274aafcc9434440820ae8539122 to your computer and use it in GitHub Desktop.
Save FelixWeichselgartner/af60d274aafcc9434440820ae8539122 to your computer and use it in GitHub Desktop.
Python script to approximate the golden ratio with the fibonacci series
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