Gauss-Seidel iterative method with no relaxation factor
    11 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Dai Nguyen
 am 27 Okt. 2020
  
    
    
    
    
    Kommentiert: Dai Nguyen
 am 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 Kommentare
Akzeptierte Antwort
  Sreeranj Jayadevan
    
 am 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]';
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Logical 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!