Gauss-Seidel Method Overview in MATLAB

Sep 5, 2024

Notes on Gauss-Seidel Method in MATLAB

Introduction

  • Course on scientific computing using MATLAB
  • Previous lecture covered iterative methods for solving linear systems (Jacobi method)
  • Today's focus: Gauss-Seidel method

Convergence Conditions

  • Gauss-Seidel method is convergent if the spectral radius (( \rho(H) )) of the convergence matrix ( H ) is less than 1.
  • Spectral radius defined as:
    [ \rho(H) = \max { |\lambda| : \lambda \text{ is an eigenvalue of } H } ]
  • Convergence matrix is defined as:
    [ H = -L + D^{-1}U ]
    where
    • ( L ) = lower triangular part of matrix
    • ( U ) = upper triangular part of matrix
    • ( D ) = diagonal part of matrix
  • Rate of convergence is given by:
    [ -\log(\rho(H)) ]

MATLAB Code Development

  • Function definition for Gauss-Seidel method:
    function x = gauss_seidel(A, b, x0, tolerance)  
    
    • Parameters:
      • A: Coefficient matrix
      • b: Right-hand side vector
      • x0: Initial guess
      • tolerance: Desired accuracy

Code Structure

  1. Initialization

    • Determine matrix size ( n )
    • Initialize solution vector ( x ) with zeros
    • Start error at 1 for the while loop
  2. Iteration Loop

    • While error > tolerance and iterations < 100:
      • Update solution using the formula:
      • Break down the matrix into lower, upper, and diagonal components
      • Numerical calculations for ( x_n )
  3. Error Calculation

    • Find the error as the norm of the difference between the new and old estimates
  4. Display Results

    • Print out the results for each iteration
    • Show eigenvalues and spectral radius

Example Runs

  • Tested various initial conditions and matrix setups:
    • 3x3 systems: convergence and divergence cases showcased.
    • Rate of convergence related to the spectral radius values observed.
    • Different initial approximations yield similar convergence behavior.
  • 4x4 systems demonstrated similar behavior with variations in iterations based on initial conditions.

Conclusions

  • Gauss-Seidel method is effective for solving linear systems but requires diagonal dominance for guaranteed convergence.
  • Importance of spectral radius in determining convergence speed and behavior.
  • The next lecture will address more problems related to iterative methods.