HP 12C Fibonacci Sequence - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: HP 12C Fibonacci Sequence (/thread-8844.html) |
HP 12C Fibonacci Sequence - Gamo - 08-16-2017 05:16 AM Here is the HP 12C program to find Fibonacci Sequence accurate up to 40 Anyone have a better solution? Gamo RE: HP 12C Fibonacci Sequence - BartDB - 08-16-2017 09:06 AM (08-16-2017 05:16 AM)Gamo Wrote: Here is the HP 12C program to find Fibonacci Sequence accurate up to 40 Hi, for interest see posts #2 & #3 in this thread in the Software Library: http://www.hpmuseum.org/forum/thread-8352-post-73315.html?highlight=fibonacci#pid73315 Best regards RE: HP 12C Fibonacci Sequence - Dieter - 08-16-2017 04:38 PM (08-16-2017 05:16 AM)Gamo Wrote: Here is the HP 12C program to find Fibonacci Sequence accurate up to 40 Your program implements an interesting formula that calculates the Fibonacci numbers directly instead of the usual approach with adding the two previous ones. I did not know this before, but it seems to be the Moivre-Binet formula: \[F_n = \frac{1}{\sqrt{5}} \left [ \left ( \frac{1+\sqrt{5}}{2} \right )^n - \left ( \frac{1-\sqrt{5}}{2} \right )^n \right ] \] A straightforward implementation does not require any registers and could be done like this: Code: 01 ENTER (08-16-2017 05:16 AM)Gamo Wrote: Anyone have a better solution? Since for n≥0 the second term is always less than 1/2 it doesn't have to be calculated. Simply round \(\frac{1}{\sqrt{5}} \left (\frac{1+\sqrt{5}}{2} \right )^n\) to the nearest integer. That's what the following program does. Code: 01 ENTER On the 10-digit 12C this also works correctly up to n=40. Above that the results are a bit larger than expected because the 10-digit value of \(\Phi\) is slightly high while \(\sqrt{5}\) in the denominator is slightly low. That's also why the rounding function in the above code does not add 0,5 but 0,3. BTW, using code boxes like this instead of attaching a PDF (which is only available after login) may be the better solution. Dieter RE: HP 12C Fibonacci Sequence - joaomario - 02-15-2023 05:32 PM I have come to a code to run the Fibonacci Sequence with just 13 steps! No data need to inupted in memories or registers, just add the code and press R/S Please, add a star to the repo if you like, that means a lot to me: https://github.com/joaomariowd/hp-12c |