# Gauss-Seidel method

(Difference between revisions)
 Revision as of 20:46, 15 December 2005 (view source)Tsaad (Talk | contribs) (towards a uniform notation for linear systems : A*Phi = B)← Older edit Revision as of 01:02, 19 December 2005 (view source)Jasond (Talk | contribs) (Added more material)Newer edit → Line 1: Line 1: + == Introduction == + We seek the solution to set of linear equations:
We seek the solution to set of linear equations:
- :$A \cdot \Phi = B$
+ :$A \phi = b$
- For the given matrix '''A''' and vectors '''X''' and '''Q'''.
+ In matrix terms, the the Gauss-Seidel iteration can be expressed as - In matrix terms, the definition of the Gauss-Seidel method can be expressed as :
+ - $+ - \phi^{(k)} = \left( {D - L} \right)^{ - 1} \left( {U\phi^{(k - 1)} + b} \right) + -$
+ - Where '''D''','''L''' and '''U''' represent the diagonal, lower triangular and upper triangular matrices of coefficient matrix '''A''' and k is iteration counter.
+ - The pseudocode for the Gauss-Seidel algorithm:
+ : + \phi^{(k)}  = \left( {D - L} \right)^{ - 1} \left( {U\phi^{(k - 1)}  + b} \right), + - === Algorithm === + where $D$, $L$ and $U$ represent the diagonal, lower triangular and upper triangular matrices of coefficient matrix $A$ and $k$ is the iteration count.  This matrix expression is mainly of academic interest, and is not used to program the method.  Rather, an element-based approach is used: - ---- + - :    Chose an intital guess $X^{0}$ to the solution
+ :$- : for k := 1 step 1 untill convergence do + \phi^{(k)}_i = \frac{1}{a_{ii}} \left(b_i - \sum_{ji}a_{ij}\phi^{(k)}_j\right),\, i=1,2,\ldots,n. +$ + + Note that the computation of $\phi^{(k)}_i$ uses only those elements of $\phi^{(k+1)}$ that have already been computed.  This means that no additional storage is required, and the computation can be done in place ($\phi^{(k+1)}$ replaces $\phi^{(k)}$).  While this might seem like a rather minor concern, for large systems it is unlikely that every iteration can be stored.  Thus, unlike the [[Jacobi method]], we do not have to do any vector copying should we wish to use only one storage vector.  The iteration is generally continued until the changes made by an iteration are below some tolerance. + + == Algorithm == + :    Chose an initial guess $\phi^{0}$
+ :    for k := 1 step 1 until convergence do
::  for i := 1 step until n do
::  for i := 1 step until n do
:::  $\sigma = 0$
:::  $\sigma = 0$
Line 28: Line 34: ::  check if convergence is reached ::  check if convergence is reached :    end (k-loop) :    end (k-loop) - ---- - - - ---- - Return to [[Numerical methods | Numerical Methods]]

## Introduction

We seek the solution to set of linear equations:

$A \phi = b$

In matrix terms, the the Gauss-Seidel iteration can be expressed as

$\phi^{(k)} = \left( {D - L} \right)^{ - 1} \left( {U\phi^{(k - 1)} + b} \right),$

where $D$, $L$ and $U$ represent the diagonal, lower triangular and upper triangular matrices of coefficient matrix $A$ and $k$ is the iteration count. This matrix expression is mainly of academic interest, and is not used to program the method. Rather, an element-based approach is used:

$\phi^{(k)}_i = \frac{1}{a_{ii}} \left(b_i - \sum_{ji}a_{ij}\phi^{(k)}_j\right),\, i=1,2,\ldots,n.$

Note that the computation of $\phi^{(k)}_i$ uses only those elements of $\phi^{(k+1)}$ that have already been computed. This means that no additional storage is required, and the computation can be done in place ($\phi^{(k+1)}$ replaces $\phi^{(k)}$). While this might seem like a rather minor concern, for large systems it is unlikely that every iteration can be stored. Thus, unlike the Jacobi method, we do not have to do any vector copying should we wish to use only one storage vector. The iteration is generally continued until the changes made by an iteration are below some tolerance.

## Algorithm

Chose an initial guess $\phi^{0}$
for k := 1 step 1 until convergence do
for i := 1 step until n do
$\sigma = 0$
for j := 1 step until i-1 do
$\sigma = \sigma + a_{ij} \phi_j^{(k)}$
end (j-loop)
for j := i+1 step until n do
$\sigma = \sigma + a_{ij} \phi_j^{(k-1)}$
end (j-loop)
$\phi_i^{(k)} = {{\left( {b_i - \sigma } \right)} \over {a_{ii} }}$
end (i-loop)
check if convergence is reached
end (k-loop)