fibonacci
Fibonacci numbers.
Category: Mathematics > Number Theory
Syntax
F = fibonacci(n)
Returns the n-th Fibonacci number, with F_0 = 0 and F_1 = 1.
Description
Each Fibonacci number is the sum of the two before it: F_n = F_(n-1) + F_(n-2). The ratio of consecutive terms tends to the golden ratio. Doubles hold the numbers exactly only up to about F_78, after which they are rounded.
For large indices use a symbolic argument: fibonacci(sym(100)) returns the exact 21-digit integer.
Input arguments
n- Integer scalar or array. Use
sym(n)for exact values of large indices.
Output arguments
F- Fibonacci numbers: doubles for numeric input, exact integers for symbolic input.
Example
First terms and an exact large one
fibonacci(0:10)
fibonacci(sym(100))
Output
ans = 1×11
0 1 1 2 3 5 8 13 21 34 55
ans = 354224848179261915075
Notes
Negative indices are not handled like MATLAB, which follows F(-n) = (-1)^(n+1)*F(n); MatLivre returns 0. The two-argument polynomial form is not supported either.