Reputation: 55
I am trying to create a Fibonacci number with high n by using matrix exponential but it gives me negative result. I have tried to change the integer objects but failed.
import numpy as np
def matrixmul(a,n):
a=np.array([[1,1],[1,0]])
return ((np.array([1,1],[1,0], dtype=np.object))**n)
matrixMul(a,100)
my output is array([[-1869596475, -980107325], [ -980107325, -889489150]]) but it was wrong. there should not be any negative number.
Upvotes: 0
Views: 94
Reputation: 81
It's hard to answer on your question. Your code have some bugs:
You haven't initialize a
Also name of defined function is different than used (python is case-sensitive)
Then in function you are not using a
(because it is not in return)
And most important thing is that you can not use **n
too get exponential of matrix. Instead you can try to find right function in scipy
library. Probably expm()
function can be right for this perpuse.
Upvotes: 1