note 74444 added to ref.math

From: Date: Wed, 11 Apr 2007 18:55:49 +0000
Subject: note 74444 added to ref.math
Groups: php.notes 
Request: Send a blank email to php-notes+get-125306@lists.php.net to get a copy of this message
Here is another way of calculating the nth term of the Fibonacci sequence, based on Binet's formula (see http://en.wikipedia.org/wiki/Fibonacci_series#Closed_form_expression for more information on this). In this example, it would display the 17th term of the Fibonacci sequence. <?php $n = 17; // Sets a value for $n, the nth term $phi = (1 + sqrt(5)) / 2; // Sets the value of phi for use in the formula $u = (pow($phi, $n) - pow(1 - $phi, $n)) / sqrt(5); echo "U<sub>$n</sub> = $u"; ?> Here is a script that lists the Fibonacci sequence from whatever two terms you specify, in this example from the 12th term to the 27th term (inclusive). <?php $f = 12; // Sets the 'f'th term, the term from which to start listing $t = 27; //Sets the 't'th term, the term at which to stop listing $phi = (1 + sqrt(5)) / 2; // Sets the value of phi for use in the formula while($f <= $t) { $u = (pow($phi, $f) - pow(1 - $phi, $f)) / sqrt(5); echo "U<sub>$f</sub> = $u<br>\n"; $f++; } ?> ---- Server IP: 87.124.64.96 Probable Submitter: 86.20.183.53 ---- Manual Page -- http://www.php.net/manual/en/ref.math.php Edit -- https://master.php.net/note/edit/74444 Del: integrated -- https://master.php.net/note/delete/74444/integrated Del: useless -- https://master.php.net/note/delete/74444/useless Del: bad code -- https://master.php.net/note/delete/74444/bad+code Del: spam -- https://master.php.net/note/delete/74444/spam Del: non-english -- https://master.php.net/note/delete/74444/non-english Del: in docs -- https://master.php.net/note/delete/74444/in+docs Del: other reasons-- https://master.php.net/note/delete/74444 Reject -- https://master.php.net/note/reject/74444 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125306) next »