# Fibonacci Sequence - Faster method?

Just decided to make a quickie Fibonacci Sequence via jQuery and I was wondering if anybody can think of a faster way to interpret it? I can type pretty much any number in and it returns in a fraction of a second.

Can anybody think of a quicker method to calculate a specific Fibonacci number?

http://jsfiddle.net/st9sgrcx/1/

\$(function(){
var counter = 1,
fibo = [0,1],
temp = 0,
whichOne = prompt("Which fibonnaci number do you want?");
function fib(prev, cur){
temp = prev + cur;
fibo.push(temp);
counter = temp;
temp = cur;
}
for(var i=0; i<whichOne; i++){
fib(temp, counter);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

• I suppose I could ignore the array and just keep the current and temp numbers as a suggestion? – Nicholas Hazel Sep 6 '15 at 21:50

$$F_n = \frac{\phi^n - \psi^n}{\sqrt{5}}$$ … where $\phi = \dfrac{1 + \sqrt{5}}{2}$ and $\psi = \dfrac{1 - \sqrt{5}}{2}$.
• I would, in some cases, recommend raising ((1 1) (1 0))^n to get the nth fib. sqrt(5) needs more and more precision as F_n gets larger, and therefore it is more computationally expensive to calculate sqrt(5) at those sizes of F_n. – Dair Sep 7 '15 at 10:08