matlab if 后总出错,Matlab:If语句中的不等式导致错误(Matlab: Inequality in If statement results in error)...

I apologize in advance, I'm sure the answer to this question is quite trivial, unfortunately I am just not sure what is going on.

I am trying to run the following code

a(1) = -2;

b(1) = 2;

c(1) = 0;

for i = 1:15

if cubicPoly(a(i))*cubicPoly(c(i)) < 0

a(i+1) = a(i);

b(i+1) = c(i);

else

a(i+1) = c(i);

b(i+1) = b(i);

end

end

but when I do I receive the error message

Index exceeds matrix dimensions.

Error in Assignment2 (line 31)

if cubicPoly(a(i))*cubicPoly(c(i)) < 0

If I evaluate my cubic polynomial function cubicPoly normally, everything works just fine. But inside the for/if loop when evaluated at the sequences a(i) and c(i) it results in an error.

Any help would be appreciated.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值