Published on 28 April 2022 (Updated: 25 September 2022)

Welcome to the Fibonacci in Matlab page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

functionf=fibonacci(n)ifischar(n)error('Usage: please input the count of fibonacci numbers to output')endifn<0error('Usage: please input a non-negative integer')endifnot(n==round(n))error('Usage: please input an integer, not a floating point')enda(1)=1;a(2)=1;fori=1:na(i+2)=a(i+1)+a(i);endf=mat2str(a);end

Note: The solution shown above is the current solution in the Sample Programs repository as of Nov 05 2019 15:10:54. The solution was first committed on Oct 24 2019 15:37:31. As a result, documentation below may be outdated.