斐波那契序列无需在八度中循环
我正在尝试创建一个没有八度 for 循环的斐波那契序列,但我得到的只是错误,我完全被困在这里。关于如何处理这个问题的任何想法
x(1)=1;
x(2)=1;
m=3:10
x(m)=x(m-1)+x(m-2)
错误:x(9):超出范围 2(尺寸为 1x2)
我期待获得第一个 10 斐波那契数列,但它不起作用
I'm trying to create a Fibonacci sequence without for loop in octave, but all I get is error and I'm totally stuck here. Any ideas on how to deal with this
x(1)=1;
x(2)=1;
m=3:10
x(m)=x(m-1)+x(m-2)
error: x(9): out of bound 2 (dimensions are 1x2)
I was expecting getting the 1st 10 Fibonacci sequence but it isn't working
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,八度不会在每个步骤(据我所知)重新计算就位的矢量化运算符(也不是MATLAB),因此
您可以使用评论中提到的封闭形式的表达式,或者只是做一个简单的表达式环形:
Unfortunately, Octave does not recalculate in-place vectorized operators at each step (nor MATLAB, as far as I'm aware of), so
You can either use a closed-form expression, as mentioned on the comments, or just do a simple loop: