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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ricky fajar
le 19 Nov 2021
Commenté : ricky fajar
le 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 commentaires
Réponse acceptée
Cris LaPierre
le 19 Nov 2021
If you need a specific number of iteractions, use a for loop instead of a while loop.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!