fibonacci function in 2016

2 views (last 30 days)
Eric Busch
Eric Busch on 7 Nov 2017
Edited: David Goodmanson on 7 Nov 2017
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.

Answers (2)

David Goodmanson
David Goodmanson on 7 Nov 2017
Edited: David Goodmanson on 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.

Walter Roberson
Walter Roberson on 7 Nov 2017
fibonacci = @(n) feval(symengine,'numlib::fibonacci',n);
Requires the Symbolic Toolbox.

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!