Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Fibonacci
Date: Sun, 11 Apr 2010 08:59:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <hps30o$821$1@fred.mathworks.com>
References: <hprijn$3bl$1@fred.mathworks.com> <hprohm$l1n$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1270976344 8257 172.30.248.37 (11 Apr 2010 08:59:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 11 Apr 2010 08:59:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:625472

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hprohm$l1n$1@fred.mathworks.com>...
> "Jake " <nathan.a2000@googlemail.com> wrote in message <hprijn$3bl$1@fred.mathworks.com>...
> > function fib(n)
> > int n;
> > if(n==0 ) return;
> > else return n * fib(n-1);  // line 7
> > .......
> -------------------------
>   Besides the serious flaws pointed out by James and Matt, there are other difficulties with what you have written here, Jake.  First of all, you seem to confuse the Fibonacci series with factorials.  Where did you ever get such a strange notion?  They are by no means the same entity.
> 
>   Secondly, if you eventually do manage to write a correct version using recursion, as you attempted to do with your present version, you will find that because the iteration involved with fibonacci numbers requires looking up two previous fibonacci numbers, then for a large number of terms out, the number of recursive calls will grow exponentially.  The tenth term will need the ninth and eighth terms.  These in turn will need the eighth and seventh and again the seventh and sixth.  This goes on all the way back to the first two terms.  For terms very far out in the series the number of these repeated calls for the same previous term becomes very large indeed.  That is not an efficient way to do mathematics.  The fibonacci series is not a good candidate for recursion and you should use a different method.
> 
> Roger Stafford

  I confess I was a little too disparaging of the recursion method.  In point of fact there is a way of making recursive calls for generating the fibonacci series which avoids the difficulties I previously mentioned.  You simply have to require that each call return a pair of consecutive fibonacci numbers..

Roger Stafford