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?
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    ricky fajar
 am 19 Nov. 2021
  
    
    
    
    
    Kommentiert: ricky fajar
 am 20 Nov. 2021
            %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'])
0 Kommentare
Akzeptierte Antwort
  Cris LaPierre
    
      
 am 19 Nov. 2021
        If you need a specific number of iteractions, use a for loop instead of a while loop.
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Resizing and Reshaping Matrices 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!

