﻿ Deriving a Non-Recurisve Fibonacci Function Using Linear Algebra

# Deriving a Non-Recursive Fibonacci Function Using Linear Algebra

## Derivation

Here's the recursive Fibonacci function: f 0 0 , f 1 1 , f n f n 1 f n 2 This produces the Fibonacci sequence 0 1 1 2 3 5 8 13 ... . The Fibonacci sequence is computable using matrix multiplication. F n f n f n 1 f n 1 f n 2 F 0 F 0 0 1 1 1 0 1 1 1 1 1 1 2 F 1 F n F 0 f n f n 1 f n 1 f n 2 0 1 1 1 f n 0 f n 1 1 f n 1 f n 1 1 f n 1 0 f n 2 1 f n 1 1 f n 2 1 f n 1 f n 2 f n 2 f n 3 F n 1 F 0 n F n So given that specific matrix, sequential matrix multiplications produce sequential Fibonacci numbers. If F0 is diagonalizable then we can write: F 0 Q D Q D λ 1 0 0 λ 2 Q v 1 v 2 Where λn are the eigenvalues and vn are the eigenvectors for F0. If there are exactly two eigenvalues then the matrix is diagonalizable. We can find the eigenvalues by solving for t when: 0 F 0 t I n t 1 1 1 t t 1 t 1 t 2 t 1 t 1 ± 5 2 So there are two eigenvalues and the matrix is diagonalizable: λ 1 1 2 5 4 , λ 2 1 2 5 4 We can find the eigenvectors by solving for vn in the following: F 0 λ n I v n 0 λ n 1 1 1 λ n v n 1 v n 2 0 λ n v n 1 v n 2 λ n v n 2 v n 2 v n 1 0 0 v n 1 λ n So now we know Q 1 1 λ 1 λ 2 And find that Q 1 λ 2 λ 1 λ 2 1 λ 1 1 Since its diagonalizable we can easily find the powers even without sequential matrix multiplies. F 0 n Q D Q Q D Q ... Q D Q Q D n Q Because D is a diagonal matrix: D n λ 1 n 0 0 λ 2 n Now its just several matrix multiplies until we have a formula. T D n Q * λ 1 n λ 2 λ 1 * λ 2 n λ 2 λ 1 F 0 n Q T f n F 0 n 1 2 λ 1 n λ 2 λ 1 λ 2 n λ 2 λ 1 λ 2 n λ 1 n λ 2 λ 1 1 2 5 4 n 1 2 5 4 n 1 2 5 4 1 2 5 4 1 5 2 n 1 5 2 n 5 1 5 n 1 5 n 2 n 5

## Calculate

Calculate the nth Fibonacci number using the above equation. Its implemented in JavaScript and uses floating point calculation so after some number of digits it produces incorrectly rounded values.