File Exchange

image thumbnail

FIBONACCI

version 1.0.0.0 (517 Bytes) by Mukhtar Ullah
Array of fibonacci numbers.

1 Download

Updated 26 May 2005

No License

FIBONACCI(N) for scalar N, is the N-th fibonacci number. When N is an N-D array, FIBONACCI(N) is the array of fibonacci numbers corresponding to each element of N.

Example:
>> fibonacci(magic(3))
ans =

21 1 8
2 5 13
3 34 1

>> fibonacci(-pascal(3))
ans =

1 1 1
1 -1 2
1 2 -8

Cite As

Mukhtar Ullah (2021). FIBONACCI (https://www.mathworks.com/matlabcentral/fileexchange/7711-fibonacci), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Mukhtar Ullah

This is the default behaviour of MATLAB. Type format long g;
then compute your result.

Paul Fournier

I have noticed that for n > 44, one can't get a meaningful answer for x = (1:n). It can compute n = 45, but uses scientific notation to do it (hence where the error comes from).

Onurb Fleicher

For an integer, the Fibonacci # can be written as:
FN =
(1/(5)^0.5)*(((1+5^0.5)/(2))^(N+1) - ((1-5^0.5)/(2))^(N+1))

When I use this script I get the Fibonacci of N-1. Here is an example:

The correct Fibonacci sequence is (For N = 1:8):
1 2 3 5 6 13 21 34
Using this file I get (N = 1:8):
1 1 2 3 5 8 13 21

Se what I mean...!?

Pete McAnena

Dead simple - calculates the members of the Fibonacci sequence non-recursively and very efficiently

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!