Skip to content

fibonacci

Fibonacci number

F = fibonacci(N)

  • N should be an array of non-negative real integers.
  • F is an array of the same size of N. Each element in F is the Fibonacci number of the corresponding element in N.
  • F is empty if N is empty.

Note

When an element in N is large, it's Fibonacci number given by F is a double-precision floating-point approximation.

Example 1: The first 11 Fibonacci numbers.

fibonacci(0:10)
ans =
Columns 1 through 5:
 0.000   1.000   1.000   2.000   3.000
Columns 6 through 10:
 5.000   8.000   13.00   21.00   34.00
Column 11:
 55.00

Example 2: F_{n} / F_{n-1} approximates the Golden Ratio for a large n.

fibonacci(100) / fibonacci(99)
ans =
 1.61803398874989

Example 3: Convergence of F_{n} / F_{n-1} to the Golden Ratio.

gs=fibonacci(1:30)./fibonacci(0:29);
plot(gs,'-p','MarkerFaceColor','r')
xlabel('n')
title('Approximation of Golden Ratio')

Approximation of Golden Ratio