| Regarding the golden ratio .... The nth number in Fibonacci sequence is denoted by f(n) The golden ratio is equal to the limit of f(n)/f(n-1) as n increases without limit. A recursive implementation of the nth number in the Fibonacci sequence in C: unsigned long long fib(int a) {
return a>1 ? fib(a-1)+fib(a-2) : 1;
}
The above function can take a while to execute if a is sufficiently large, on my machine fib(40) takes about a second to return a value.Time taken to execute the function fib(a) is denoted by t(a). As n increases without limit t(n)/t(n-1) approaches the golden ratio. In practise this should give you a rough value of the golden ratio. The reason this happens is because the function can only increase the return value by unity, one call at a time. |
f(n+2)=f(n+1)+f(n)
If you posit that this number has a solution in f(n)=a^x, you see that
a^(n+2)=a^(n+1)+a^n
Dividing by a^n, you get a^2=a+1, a simple quadratic with two roots, (1+sqrt(5))/2 and (1-sqrt(5))/2, or the golden ratio and approximately -0.618.
Because any constant multiple of the function will also solve the equation, a solution to f(n) will be some linear combination of f(n)=c1(1.618..)^n+c2(-0.618)^n, for constants c1 and c2. You calculate c1 and c2 to match your initial conditions.
As n increases, the second term tends to 0, so f(n+1)/f(n) approaches the golden ratio.