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 Center および File ExchangeNumber Theory についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by