This question already has an answer here:
- Numpy matrix exponentiation gives negative value 1 answer
I'm working on an implementation of the Fibonacci sequence in Numpy using the Q-Matrix method. The results are fine up till n = 47. At this point, the matrix_power
function is returning incorrect results. Any explanation about why this is happening?
import numpy
def fibonacci(n):
qmatrix = numpy.matrix([[1, 1], [1, 0]])
(a,b,c,d) = numpy.linalg.matrix_power(qmatrix,n).flatten().tolist()[0]
return b
print fibonacci(47) # Outputs -1323752223