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 views (last 30 days)
  
       Show older comments
    
    ricky fajar
 on 19 Nov 2021
  
    
    
    
    
    Commented: ricky fajar
 on 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 Comments
Accepted Answer
  Cris LaPierre
    
      
 on 19 Nov 2021
        If you need a specific number of iteractions, use a for loop instead of a while loop.
More Answers (0)
See Also
Categories
				Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
