4 ms·
The following defines the Fibonacci recurrence relation (in matrix form): [F(n+1); F(n)] = [1 1; 1 0]^n * [F(n); F(n-1)] or [F(n+1); F(n)] = [1 1; 1 0]^n * [
by ntenenz 11y ago
The following defines the Fibonacci recurrence relation (in matrix form):
[F(n+1); F(n)] = [1 1; 1 0]^n * [F(n); F(n-1)]
or
[F(n+1); F(n)] = [1 1; 1 0]^n * [1; 0] if we define F(0) = 0 and F(1) = 1.
However, we can diagonalize [1 1; 1 0] using its eigenvalues and eigenvectors (see here: http://www.wolframalpha.com/input/?i=eigenvectors+of+%7B%7B1%2C+1%7D%2C+%7B1%2C+0%7D%7D http://www.wolframalpha.com/input/?i=eigenvectors+of+%7B%7B1...).
For any diagonalizable matrix A = PDP^-1 where P is the matrix of eigenvectors and D is the matrix of eigenvalues on the diagonal, A^n = PD^nP^-1. Try to expand the A^n if you don't believe it. Using this trick, you have simplified the power of a matrix to a power of two floats, namely the eigenvalues.
- gaze 11y agoFrom this you'll end up with the closed form in terms of the golden ratio. Might as well use that.
- ntenenz 11y agoYup, you will. It's nice to show where that comes from though. :)
- conistonwater 11y agoFloats have rather limited precision for this type of computation for large n (gp's post had n=1e9). If you were to go with big-floats instead, then the resulting arithmetic will be more expensive that the straightforward big-integer arithmetic.