fibonacci function in 2016

조회 수: 1 (최근 30일)
Eric Busch
Eric Busch 2017년 11월 7일
편집: David Goodmanson 2017년 11월 7일
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.

답변 (2개)

David Goodmanson
David Goodmanson 2017년 11월 7일
편집: David Goodmanson 2017년 11월 7일
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 2017년 11월 7일
fibonacci = @(n) feval(symengine,'numlib::fibonacci',n);
Requires the Symbolic Toolbox.

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by