fibonacci function in 2016
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
David Goodmanson
am 7 Nov. 2017
Bearbeitet: David Goodmanson
am 7 Nov. 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 Kommentare
Walter Roberson
am 7 Nov. 2017
fibonacci = @(n) feval(symengine,'numlib::fibonacci',n);
Requires the Symbolic Toolbox.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Number Theory finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!