Gauss-Seidel iterative method with no relaxation factor
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dai Nguyen
le 27 Oct 2020
Commenté : Dai Nguyen
le 9 Nov 2020
Hi I want to create a Matlab code for Gauss-Seidel iterative method with no relaxation factor and use the solution using a termination tolerance=.01% for the relative approximate error. This is what I got so far. For some reason my stigma is zero and it won't able to calculate it
A= [60 -40 0; -40 60 -20; 0 -20 20]
b=[29.4; 39.2; 58.8]
x=[0 0 0 0]'
n=size(x,1);
normVal=Inf;
%%
% * _*Tolerence for method*_
tol=1e-5; itr=0;
%%
while normVal>tol
x_old=x;
for i=1:n
sigma=0;
for j=1:i-1
sigma=sigma+A(i,j)*x(j);
end
for j=i+1:n
sigma=sigma+A(i,j)*x_old(j);
end
x(i)=(1/A(i,i))*(b(i)-sigma);
end
itr=itr+1;
normVal=norm(x_old-x);
end
%%
fprintf('Solution of the system is : \n%f\n%f\n%f\n%f in %d iterations',x,itr);
0 commentaires
Réponse acceptée
Sreeranj Jayadevan
le 9 Nov 2020
I have executed the given code in MATLAB and it is giving me the required output. It seems to me that you have accidentally initialized the solution vector "x" as a 4 by 1 array. Since only three equations are involved in the problem, "x" should be a 3 by 1 array i.e
x=[0 0 0]';
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating 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!