-
-
Save agumonkey/3c4ae579b6785d2be5859de1f58e3d19 to your computer and use it in GitHub Desktop.
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 numpy as np | |
# The Fibonacii matrix | |
M = np.array([[0, 1], [1, 1]], dtype=np.float32) | |
# Compute the eigendecomposition of the matrix | |
w, v = np.linalg.eig(M) | |
inv_v = np.linalg.inv(v) | |
base_case = np.array([0, 1]).T # base case as a column vector | |
# Print the first ten values of the Fibonaci sequence | |
for i in range(1, 10): | |
result = v * (np.diag(w) ** i) * inv_v * base_case # matrix form of the solution | |
int_result = round(result[1,1]) # solution is stored in the bottom right cell | |
print(int_result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment