2.64286

2.6 | 17 ratings Rate this file 14 downloads (last 30 days) File Size: 1.36 KB File ID: #22421

Fibonacci

by Shahab Anbarjafari

 

12 Dec 2008

Code covered by BSD License  

The following function generate the fibinacci series up to the sequence number m.

Download Now | Watch this File

File Information
Description

The following function generate the fibinacci series up to the sequence number m which should be a positive integer, it may takes several minutes for big numbers of m, for a typical working station m>20 is taking considerable amount of time to be processed.

Feel free to contact us for any furthur information:
 {hasan.demirel, shahab.jafari}@emu.edu.tr
  http://faraday.ee.emu.edu.tr/shahab
  http://faraday.ee.emu.edu.tr/hdemirel
  (c) Demirel and Anbarjafari -2008

Acknowledgements
This submission has inspired the following:
Fibonacci and Lucas numbers
MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (20)
12 Dec 2008 Anon

Why going for recursion, when there are other ways to solve it?

Your function:
>>tic;a = fibonacci(30);toc
Elapsed time is 57.611550 seconds.
>> a

a =

      832040

David Terr's function
http://www.mathworks.com/matlabcentral/fileexchange/5093

>> tic;a = fibonacci2(30);toc
Elapsed time is 0.000082 seconds.
>> a

a =

      832040

12 Dec 2008 alain boyer  
13 Dec 2008 i posh

Shahab, thanks for the example....

13 Dec 2008 Jos

There are so many ways to arrive at a fibonacci number: see http://blogs.mathworks.com/loren/2006/05/17/fibonacci-and-filter/

This submission is not so bad in itself, although the help lacks an H1 line (used by LOOKFOR) and an example. However, as this is clearly a product of a programming exercise, I do not think this is worthwhile to post it here on the FEX. Hence my 2 stars.

13 Dec 2008 Shahab Anbarjafari

Thanks for your comment Jos, well the reason that I post this file was some of my students want an example of using a recursive function MATLAB, so I let them have it by posting it here, not only them but maybe some other people may want to just have a review of recursive function.
I appreciate you sparing your time on commenting my programme.

14 Dec 2008 Jeff Burkey

Shahab, cyclonic programming is the most cpu time intensive technique (i.e. slow). I would like to make the suggestion, why not teach your students multi-dimensional techniques which is what Matlab excels at best for a platform and is orders of magnitude faster. That said, working with large datasets certainly may require loops, or at best a combination of loops and dimensional math. Plus if you go parallel processing deminsonal math would be prefered. Regards, Jeff.

21 Dec 2008 Derek O'Connor

This is a very poor example for demonstrating recursion and my lead naive students to believe that all recursion is inefficient.

 This is not true: the recursive Fibonacci generator is a classic example of using a good tool for the wrong job.

For example, fibonacci(25) makes 243,028 fibonacci() calls, all but 25 of them superfluous.

If you really need to calculate Fibonacci numbers then something such as the following function will be much faster.

function result = IFib(n);
F0 = 0;
F1 = 1;
for k = 2:n
    F2 = F1 + F0;
    F0 = F1;
    F1 = F2
end;
result = F2;

If you need to demonstrate recursion to students then choose a better example, such as Binary Search of an ordered table. Many more examples can be found in any good book on algorithms.

Derek O'Connor

25 Mar 2009 Xu Wings

not so professional

30 Mar 2009 Kemal  
31 Mar 2009 Hal 9000

poorly written

01 Apr 2009 M P

Don’t listen the bad opinions, the despise-actions are symbols of envy. Big first position. Regards

01 Apr 2009 Shahab Anbarjafari

:)

02 Apr 2009 Kemal  
02 Apr 2009 Shahab Anbarjafari

DEar Marco, Thanks for spending your time to do rating :) From what I can see you always give 1 ;) good work mate :)

05 Apr 2009 V. Poor  
05 Apr 2009 alain boyer  
05 Apr 2009 Xing Yu  
05 Apr 2009 Robin Torres  
15 Apr 2009 Mustafa  
24 Apr 2009 Xu Wings  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
mathematics Cristina McIntire 12 Dec 2008 15:17:09
fibonacci sequence Shahab Anbarjafari 12 Dec 2008 15:17:16
mathematics Shahab Anbarjafari 12 Dec 2008 15:17:16
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com