I keep on getting 'index exceeds array bounds'
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
>> 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 Kommentare
Antworten (1)
Ji Hoon Jeong
am 5 Sep. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!