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.