0% found this document useful (0 votes)
48 views16 pages

Clase 8 Calculo Numerico I

Here is a MATLAB M-file that implements the Gauss-Seidel method: function [x,resnorm,iterations] = GaussSeidel(A,b,x0,tol,maxiter) % GaussSeidel - Solve a linear system Ax=b using Gauss-Seidel iteration % % Inputs: % A - Coefficient matrix % b - Right hand side vector % x0 - Initial guess % tol - Tolerance for convergence test % maxiter - Maximum number of iterations n = length(b); % Number of equations x = x0; % Initialize solution vector resnorm = Inf; % Initialize residual norm iterations

Uploaded by

enrique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views16 pages

Clase 8 Calculo Numerico I

Here is a MATLAB M-file that implements the Gauss-Seidel method: function [x,resnorm,iterations] = GaussSeidel(A,b,x0,tol,maxiter) % GaussSeidel - Solve a linear system Ax=b using Gauss-Seidel iteration % % Inputs: % A - Coefficient matrix % b - Right hand side vector % x0 - Initial guess % tol - Tolerance for convergence test % maxiter - Maximum number of iterations n = length(b); % Number of equations x = x0; % Initialize solution vector resnorm = Inf; % Initialize residual norm iterations

Uploaded by

enrique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Calculo Numérico I

Métodos Iterativos:
método de Gauss-Seidel

Dr. Luis Sanchez


Gauss-Siedel

• Iterative or approximate methods provide an


alternative to the elimination methods. The Gauss-
Seidel method is the most commonly used iterative
method.

• The system [A]{X}={B} is reshaped by solving the


first equation for x1, the second equation for x2, and
the third for x3, …and nth equation for xn. We will
limit ourselves to a 3x3 set of equations.
Gauss-Siedel

a11x1  a12 x2  a13 x3  b1 b1  a12 x2  a13 x3


x1 
a11

a21x1  a22 x2  a23 x3  b2  x2 


b2  a21x1  a23 x3
a22
b3  a31x1  a32 x2
x1 
a31x1  a32 x2  a33 x3  b3 a33

Now we can start the solution process by choosing


guesses for the x’s. A simple way to obtain initial guesses
is to assume that they are zero. These zeros can be
substituted into x1 equation to calculate a new x1=b1/a11.
Gauss-Siedel

• New x1 is substituted to calculate x2 and x3. The


procedure is repeated until the convergence
criterion is satisfied:

new
x x old
 a ,i  i
new
i
100%   s
x i
Jacobi iteration Method

An alternative approach, called Jacobi iteration,


utilizes a somewhat different technique. This technique
includes computing a set of new x’s on the basis of a
set of old x’s. Thus, as the new values are generated,
they are not immediately used but are retained for the
next iteration.
Gauss-Siedel

The Gauss-Seidel method The Jacobi iteration method


Convergence Criterion for Gauss-Seidel Method

• The gauss-siedel method is similar to the technique of


fixed-point iteration.
• The Gauss-Seidel method has two fundamental problems
as any iterative method:
1. It is sometimes non-convergent, and
2. If it converges, converges very slowly.
• Sufficient conditions for convergence of two linear
equations, u(x,y) and v(x,y) are:

u u
 1
x y
v v
 1
x y
Convergence Criterion for Gauss-Seidel
Method (cont’d)
• Similarly, in case of two simultaneous equations, the
Gauss-Seidel algorithm can be expressed as:
b1 a12
u (x 1 , x 2 )   x2
a11 a11
b 2 a21
v (x 1 , x 2 )   x1
a22 a22
u u a12
0 
x 1 x 2 a11
v a21 v
 0
x 1 a22 x 2
Convergence Criterion for Gauss-Seidel
Method (cont’d)
Substitution into convergence criterion of two linear
equations yield:
a12 a21
 1, 1
a11 a22
In other words, the absolute values of the slopes must be
less than unity for convergence:
a11  a12 For n equations
n

a22  a21 aii  a


j 1
i, j

j i

That is, the diagonal element must be greater than the off-
diagonal element for each row.
Gauss-Siedel Method- Example 1
7.85  0.1x2  0.2 x3
 3  0.1 0.2   x1   7.85  x1  3
0.1   x    19.3  19.3  0.1x1  0.3 x3
 7  0.3  2     x2 
7
0.3  0.2 10   x3   71.4  x3  71.4  0.3 x1  0.2 x2
10

• Guess x1, x2, x3= zero for the first guess


Iter. x1 x2 x3 |ea,1|(%) |ea,2| (%) |ea,3| (%)
0 0 0 0 - - -
1 2.6167 -2.7945 7.005610 100 100 100
2 2.990557 -2.499625 7.000291 12.5 11.8 0.076
Improvement of Convergence Using Relaxation

x i
new
  x i
new
 1     x old
i

• Where  is a weighting factor that is assigned a value


between [0, 2]
• If  = 1 the method is unmodified.
• If  is between 0 and 1 (under relaxation) this is
employed to make a non convergent system to
converge.
• If  is between 1 and 2 (over relaxation) this is
employed to accelerate the convergence.
Gauss-Siedel Method- Example 2

 8 x1  x2  2 x3  20
 3x1  x2  7 x3  34
2 x1  6 x2  x3  38
8x 1  x 2  2x 3  20
Rearrange so that the
equations are 2x 1  6x 2  x 3  38
diagonally dominant
3x 1  x 2  7 x 3  34

 20  x2  2 x3  38  2 x1  x3  34  3x1  x2
x1  x2  x3 
8 6 7
Gauss-Siedel Method- Example 2

iteration unknown value a maximum a


0 x1 0
x2 0
x3 0
1 x1 2.5 100.00%
x2 7.166667 100.00%
x3 -2.7619 100.00% 100.00%
2 x1 4.08631 38.82%
x2 8.155754 12.13%
x3 -1.94076 42.31% 42.31%
3 x1 4.004659 2.04%
x2 7.99168 2.05%
x3 -1.99919 2.92% 2.92%
Gauss-Siedel Method- Example 2
The same computation can be developed with relaxation where
 = 1.2
First iteration:
 20  x 2  2 x3  20  0  2(0)
x1    2.5
8 8
Relaxation yields: x1  1.2(2.5)  0.2(0)  3
38  2x 1  x 3 38  2(3)  0
x2    7.333333
6 6
Relaxation yields: x2  1.2(7.333333)  0.2(0)  8.8
 34  3x1  x 2  34  3(3)  8.8
x3    2.3142857
7 7
Relaxation yields: x3  1.2(2.3142857)  0.2(0)  2.7771429
Gauss-Siedel Method- Example 2
Iter. unknown value relaxation a maximum a
1 x1 2.5 3 100.00%
x2 7.3333333 8.8 100.00%
x3 -2.314286 -2.777143 100.00% 100.000%
2 x1 4.2942857 4.5531429 34.11%
x2 8.3139048 8.2166857 7.10%
x3 -1.731984 -1.522952 82.35% 82.353%
3 x1 3.9078237 3.7787598 20.49%
x2 7.8467453 7.7727572 5.71%
x3 -2.12728 -2.248146 32.26% 32.257%
4 x1 4.0336312 4.0846055 7.49%
x2 8.0695595 8.12892 4.38%
x3 -1.945323 -1.884759 19.28% 19.280%
MATLAB M-file: GaussSeidel
Before developing an algorithm, let us first recast Gauss-Seidel in a
form that is compatible with MATLAB’s ability to perform matrix
operations

You might also like