i have made a matlab code of gauss-siedel but there's a slight problem . i need to make the output print 20 iteration but i only get 18. any advice?

1 次查看(过去 30 天)
%6x-y-z=19
%3x+4y+z=26
%x+2y+6z=22
%initial values for y and z is 0
%x=19+y+z/6
%y=26-3x-z/4
%z=22-x-2y/6
clear;clc;format('long','g');
i=1;
y(i)=0;
z(i)=0;
error_x(i)=1;
%gauss-siedel opperation begin
while error_x(i) >= 0.00000000000000001
x(i+1)=((19 + y(i) +z(i) )/6);
y(i+1)=((26 - (3*x(i+1))- z(i)) /4);
z(i+1)=((22 - x(i+1)- 2*y(i+1)) /6);
error_x(i+1)=abs((x(i+1)-x(i))/x(i+1))*100;
error_y(i+1)=abs((y(i+1)-y(i))/y(i+1))*100;
error_z(i+1)=abs((z(i+1)-z(i))/z(i+1))*100;
i=i+1;
end
%print out the value
disp(' x error(%)');
disp([x', error_x'])
disp(' y error(%)');
disp([y', error_y'])
disp(' z error(%)');
disp([z', error_z'])

采纳的回答

Cris LaPierre
Cris LaPierre 2021-11-19
If you need a specific number of iteractions, use a for loop instead of a while loop.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by