Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
So I'm a beginner at programming in general and am using TI-BASIC as an introduction. Right now I have been making sense of recursion in chapter 4 as best as I can.

Let me first say that this topic is especially frustrating because the concept itself makes sense when it is explained, but when the author says to go ahead and test your comprehension by translating the Fibonacci solver into a recursive program I become lost.

So after many failures I decided to step back and research more general information on both recursion and the Fibonacci sequence. Then after I mulled over the subject for some time I attempted it again, and, after more painful experimentation I came up with a program that seems to actually work Idea. Now I must say my understanding is still somewhat tenuous so I'll type out the code I came up with and if anyone has any suggestions I'd be happy to consider them so that I get a better grasp on recursion.

Here's the driver function:
PROGRAM:FIBORECC
:Disp "CALCULATES NTH","FIBONACCI NUM
:Prompt N
:If N=1 or N=2
:Then
:Pause 1
:Else
:prgmZFIB
:Disp F

Here's the subprogram or whatever you want to call it:
PROGRAM:ZFIB
:If N=2
:Then
:1→A
:1→B
:Else
:A+B→F
:B→A
:F→B
:N-1→N
:prgmZFIB
:End

When I came up with this I thought for sure it wouldn't work but it did. It still feels like maybe I'm missing something but for now at least it functions. I look forward to continuing my studies with this book as a guide.
Okay well at first glance, this seems alright, on the maths side though, you don't need recursion to find the nth fibonacci number, simply using binet's formula: (((1+√5)/2)^n - ((1-√5)/2)^n)/√5
(where n is the position of the number in the sequence) will output the value at that position. Of course, this will be smaller and faster than counting up Razz
mr womp womp wrote:
Okay well at first glance, this seems alright, on the maths side though, you don't need recursion to find the nth fibonacci number, simply using binet's formula: (((1+√5)/2)^n - ((1-√5)/2)^n)/√5
(where n is the position of the number in the sequence) will output the value at that position. Of course, this will be smaller and faster than counting up Razz


I appreciate the feedback. Yeah it makes sense that this is not the most efficient way to carry out a Fibonacci sequence, just needed to figure it out for the exercise. Thank you for referencing this formula. I thought I saw that when researching but it's more clear now. Thanks again! Cool
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement