Gauss–Seidel method

In numerical linear algebra, the Gauss–Seidel method, also known as the Liebmann method or the method of successive displacement, is an iterative method used to solve a linear system of equations. It is named after theGerman mathematicians Carl Friedrich Gauss and Philipp Ludwig von Seidel, and is similar to the Jacobi method. Though it can be applied to any matrix with non-zero elements on the diagonals, convergence is guaranteed if the matrix is either diagonally dominant, or symmetric and positive definite.

clc

clear

n=6;

A=[4 -1 0 -1 0 0; -1 4 -1 0 -1 0; 0 -1 4 0 0 -1; -1 0 0 4 -1 0; 0 -1 0 -1 4 -1; 0 0 -1 0 -1 4];

B=[0 5 0 6 -2 6];

X0=[0 0 0 0 0 0];

TOL=0.01;

N=50;

k=0;

for repeats=1:N

for i=1:n

sum1=0;

sum2=0;

if i ~= 1

for j=1:i-1

sum1=sum1+A(i,j)*X0(j);

end

end

if i ~= n

for j=i+1:n

sum2=sum2+A(i,j)*X0(j);

end

end

X(i)=(1/A(i,i))*(B(i)-sum1-sum2);

end

if (norm(X-X0,inf)<=TOL);

fprintf(‘Λύση του γραμμικού συστήματος με την μέθοδο Gauss-Seidel:\n’);

disp(X)

fprintf(‘Αριθμός επαναλήψεων για σύγκλιση :’);

disp(k)

return;

end

k=k+1;

for i=1:n

X0(i)=X(i);

end

end

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment