Post Reply 
(15C) Fibonacci Numbers
03-23-2017, 03:22 AM (This post was last modified: 03-23-2017 01:09 PM by Eddie W. Shore.)
Post: #1
(15C) Fibonacci Numbers
This program calculates the nth Fibonacci number. Store n in memory register 0 before running the program.

Formula: ( (1 + √5)^n – (1 - √5)^n ) / (2^n * √5)

Caution: Due to internal calculator calculation, you may not get an integer answer. You might have to round the answer manually. From Joe Horn, with thanks and appreciation for letting me post his comment:

"Hi, Eddie! I just keyed up your HP-15C program for Fibonacci numbers, and noticed that it gets wrong answers due to round-off errors much of the time. For example, with an input of 5, it should output 5, but it outputs 4.9999999998. Even rounding to the nearest integer doesn't fix the problem for inputs of 40 through 49. The only way to get the right answers for all inputs is with a loop (the usual method)." - Joe Horn

I would recommend running this program when n< 40.

Code:

Step    Key    Code
001    LBL D    42, 21, 14
002    1    1
003    ENTER    36
004    5    5
005    √     11
006    +    40
007    RCL 0    45, 0
008    Y^X    14
009    1    1
010    ENTER    36
011    5    5
012    √     11
013    -    30
014    RCL 0    45, 0
015    Y^X    14
016    -    30
017    2    2
018    RCL 0    45, 0
019    Y^X    14
020    ÷    10
021    5    5
022    √     11
023    ÷     10
024    RTN    43, 32

Example: R0 = n = 16, Output: 987
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(15C) Fibonacci Numbers - Eddie W. Shore - 03-23-2017 03:22 AM
RE: (15C) Fibonacci Numbers - Albert Chan - 08-07-2023, 10:09 PM
RE: (15C) Fibonacci Numbers - Werner - 08-08-2023, 11:05 AM
RE: (15C) Fibonacci Numbers - Albert Chan - 08-08-2023, 11:44 AM
RE: (15C) Fibonacci Numbers - Thomas Klemm - 08-06-2023, 11:06 AM
RE: (15C) Fibonacci Numbers - Joe Horn - 08-06-2023, 04:49 PM
RE: (15C) Fibonacci Numbers - Thomas Klemm - 08-06-2023, 03:16 PM
RE: (15C) Fibonacci Numbers - Thomas Klemm - 08-07-2023, 10:49 PM
RE: (15C) Fibonacci Numbers - Werner - 08-08-2023, 12:06 PM



User(s) browsing this thread: 1 Guest(s)