Re: Compution of Fibonacci
| From: | Unknown Sender | Date: | Tue, 31 Jul 2001 07:23:59 +0000 |
| Subject: | Re: Compution of Fibonacci | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60324@lists.php.net to get a copy of this message | ||
On Tue, Jul 31, 2001 at 11:59:07AM +0500, Saquib Farooq wrote:
> hi
>
> well first of all you have to remove the colon -- ";" sign from
> the end of your while loop ...... that will solve the problem for the time
> out.
> then there is problem with your code, this code will never get you
> the fibonacci since the variable a,b and c never go abone 0, see. :).
Just in case anyone is interested... If you want to find the n'th
Fibonacci number and not go through the entires sequence, you can
use the formula:
F(n) = ( P^n - (-P)^(-n) ) / sqrt(5) where P = (1 + sqrt(5))/2
and it's also possible to extend Fibonacci numbers to negative n.
Pretty fascinating (:
Also, if you have F(n) you can find F(n+1). Let x denote F(n).
F(n+1) = floor( (x + 1 + sqrt(5x^2)) / 2).
Stig