Last active
March 7, 2019 07:53
-
-
Save SuperShinyEyes/db4daad1f1bd5d671a8a89664ecc7f3b to your computer and use it in GitHub Desktop.
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
import numpy as np | |
from scipy import constants | |
def fibonacci(n): | |
"""Calculate fibonacci system in signal processing way; weighted sum of fundamental modes. | |
The complexity: O(1). | |
""" | |
p = constants.golden | |
return int(np.around( | |
(p / (np.sqrt(5) ) * np.power(p, n)) + \ | |
(1 / (np.sqrt(5) * p) * np.power(-p, -n)) | |
)) | |
for i in range(22): | |
print(fibonacci(i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment