Iterative Solution Using Gauss-Seidel Method

Filter Course


Iterative Solution Using Gauss-Seidel Method

Published by: Dikshya

Published date: 19 Jul 2023

Iterative Solution Using Gauss-Seidel Method

Iterative Solution Using Gauss-Seidel Method

The Gauss-Seidel method is an iterative technique used to solve systems of linear equations iteratively. It is an improvement over the simpler Jacobi method and converges faster for many systems. The method is particularly effective for diagonally dominant systems, where the diagonal elements of the coefficient matrix are significantly larger than the off-diagonal elements.

Algorithm:

1. Input:

- Coefficient matrix A (n x n)

- Right-hand side vector b (n x 1)

- Initial guess vector x^(0) (n x 1)

- Tolerance level tol (small positive number)

- Maximum number of iterations max_iter

2. Initialize:

- Set k = 1 (iteration counter)

- Set x = x^(0) (current approximation vector)

- Set x_new = zeros vector of size n (vector for storing the updated approximation)

3. Iterative Loop: Repeat the following steps until convergence or maximum iterations are reached.

a. For i = 1 to n:

b. Update x with the new approximation:

c. Increment the iteration counter:

d. Check for convergence:

e. Check for maximum iterations:

  • Compute the temporary sum variable sum = 0.
  • For j = 1 to n:
    • If j ≠ i, then:
      • sum = sum + A(i, j) * x(j)
  • Update the current approximation for the i-th component:
    • x_new(i) = (b(i) - sum) / A(i, i)
  • For i = 1 to n:
    • x(i) = x_new(i)
  • k = k + 1
  • Calculate the residual vector r = b - A * x.
  • Calculate the 2-norm of the residual vector ||r||.
  • If ||r|| < tol, exit the loop (convergence achieved).
  • If k > max_iter, exit the loop (maximum iterations reached).

4. Output:

- The approximate solution vector x, which is the solution to the system of linear equations Ax = b (within the specified tolerance).

Note: The convergence of the Gauss-Seidel method is not guaranteed for all systems. For some ill-conditioned or badly scaled systems, it may diverge or exhibit slow convergence. In such cases, more advanced iterative methods like the Successive Over-Relaxation (SOR) method or direct methods like LU decomposition are often preferred.

Example:

Let's illustrate the Gauss-Seidel method with a simple system of linear equations:

3x + y - z = 9
x - 4y + 2z = -6
-2x + y + 7z = 5
1. Coefficient matrix A:

| 3  1 -1 |
| 1 -4  2 |
|-2  1  7 |


2. Right-hand side vector b:

| 9 |
| -6 |
| 5 |


3. Initial guess vector x^(0):

| 0 |
| 0 |
| 0 |

 

4. Tolerance level tol: 0.0001

5. Maximum number of iterations max_iter: 100

By applying the Gauss-Seidel method following the algorithm steps, we can iteratively find the approximate solution for x.