fibonacci function in 2016
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Is the fibonacci function "fibonacci(n)" only available in the 2017 version? If not how do i use it in r2016b? I've tried using the syntax and doing the exact example but it returns an error.
0 comentarios
Respuestas (2)
David Goodmanson
el 7 de Nov. de 2017
Editada: David Goodmanson
el 7 de Nov. de 2017
Hi Eric,
If you don't have the symbolic toolbox you can do this numerically with the filter function which is part of basic Matlab, not exiled to a toolbox (so far so good).
function sN = fibon(n1,n2,N)
% the first N terms of a fibonacci series,
% where the first two terms are n1, n2.
% The traditional fibonacci series has n1 = n2 = 1.
x = zeros(1,N);
x(1) = 1;
a = [1 -1 -1];
b = [n1 n2-n1];
sN = filter(b,a,x)
end
This works up to N = 75 or so. After that, if you need more digits than supported by double precision, you can go to John D'Errico's high precision package in the file exchange, or something similar.
0 comentarios
Walter Roberson
el 7 de Nov. de 2017
fibonacci = @(n) feval(symengine,'numlib::fibonacci',n);
Requires the Symbolic Toolbox.
0 comentarios
Ver también
Categorías
Más información sobre Number Theory en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!