No BSD License  

Highlights from
FIBONACCI

3.66667

3.7 | 3 ratings Rate this file 2 Downloads (last 30 days) File Size: 802 Bytes File ID: #7711

FIBONACCI

by Mukhtar Ullah

 

24 May 2005 (Updated 26 May 2005)

Array of fibonacci numbers.

| Watch this File

File Information
Description

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

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
09 Jan 2006 Pete McAnena

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

07 Feb 2006 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...!?

25 Feb 2006 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).

27 Feb 2006 Mukhtar Ullah

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

Please login to add a comment or rating.
Updates
26 May 2005

rewritten to exploit the fact:
f(-n) = (-1)^(n+1)*f(n)

26 May 2005

improved!

Tag Activity for this File
Tag Applied By Date/Time
fibonacci Mukhtar Ullah 22 Oct 2008 07:49:07
numbers Mukhtar Ullah 22 Oct 2008 07:49:07
array Mukhtar Ullah 22 Oct 2008 07:49:07
scalar Mukhtar Ullah 22 Oct 2008 07:49:07
nd Mukhtar Ullah 22 Oct 2008 07:49:07

Contact us at files@mathworks.com