【发布时间】:2016-02-23 01:52:24
【问题描述】:
我想创建一个函数,从数组中的前两个元素开始,然后从它们创建斐波那契数列,但它会创建一个带有小数等的奇怪矩阵,它是我想要的列数的两倍每次。当我查找它时,这是我在阅读文档后想出的。
我几乎没有使用 MATLAB 的经验,而且我习惯了 python。我还没有找到真正解决我问题的任何东西。或者有帮助。
function [f,s] = fibb(nmax)
f = array(1,0);
% first two items in array are 0 and 1 respectively
for n = 3 : 1 : nmax
f(n) = [f(n-1) + f(n-2) newElem];
% Adds new entry, entry is sum of previous two
end
s = sum(f);
% sum of the sequence
【问题讨论】:
-
什么是
array(1,0)?