I keep on getting 'index exceeds array bounds'
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
>> i=1; >> x1(i)=1;x2(i)=1;x3(i)=1; >> error_x1(i)=999999999999999999999999; >> while error_x1(i)>=0.01 x1(i+1) = (7-x2(i)-3*x2(i))/2 x2(i+1) = (9-3*x1(i+1)+2*x3(i))/4 x3(i+1) = (4-x2(i+1)-x3(i+1))/1
error_x1(i+1) = abs((x1(i+1)-x1(i))/x1(i+1))*100;
error_x1(i+1) = abs((x2(i+1)-x2(i))/x2(i+1))*100;
error_x1(i+1) = abs((x3(i+1)-x3(i))/x3(i+1))*100;
i=i+1;
end
x1 =
1.0000 1.5000
x2 =
1.0000 1.6250
Index exceeds array bounds.
0 comentarios
Respuestas (1)
Ji Hoon Jeong
el 5 de Sept. de 2018
I presume this is your code.
i=1;
x1(i)=1;
x2(i)=1;
x3(i)=1;
error_x1(i)=999999999999999999999999;
while error_x1(i)>=0.01
x1(i+1) = (7-x2(i)-3*x2(i))/2
x2(i+1) = (9-3*x1(i+1)+2*x3(i))/4
x3(i+1) = (4-x2(i+1)-x3(i+1))/1
error_x1(i+1) = abs((x1(i+1)-x1(i))/x1(i+1))*100;
error_x1(i+1) = abs((x2(i+1)-x2(i))/x2(i+1))*100;
error_x1(i+1) = abs((x3(i+1)-x3(i))/x3(i+1))*100;
i=i+1;
end
The third line in your while statement is causing the problem.
x3(i+1) term in the right side of the equal sign.
Since x3(1+1) does not exist, you should change your algorithm.
0 comentarios
Ver también
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!