MATLAB: I keep getting this error index exceeds array bounds. please help me. I’m new to MATLAB

array boundsindexnewton raphson method

f1=@ (x,y) x+2*x*y-15;
f2=@ (x,y) x*y+3*x^2*y-10;
a=@ (x,y) 1+2*y;
b=@ (x,y) 2*x;
c=@ (x,y) y+6*x*y;
d=@ (x,y) x+3*x^2;
x(1)=1.5; y(1)=2.5; N=2;
for i=1:N
J=[a(x(i),y(i)) ,b(x(i),y(i)); c(x(i),y(i)) ,d(x(i),y(i))];
x(i+1)=x(i)-((f1(x(i),y(i))*d(x(i),y(i)))-(f2(x(i),y(i))*b(x(i),y(i))))/det(J);
end
[SL: in the future, to make your code easier to read, please select the code then press the {}Code button above the edit box. I've applied that formatting for this post.]

Best Answer

At the second iteration through your for loop, i is 2. On the first line of the body of the loop, you try to index y(2). However, the vector y only has one element so MATLAB (correctly) throws an error that you're trying to access an element that doesn't exist.
I think you're missing a section of code to compute y(i+1) in terms of x(i) and y(i) in your loop.