Home > Python > Solve Linear Equations

Ch. 9.3 Gauss-Seidel Method

Chapters Index
Program 1

Gauss-Seidel Method

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

Solve the following system of linear equations using the Gauss-Seidel method until convergence to a tolerance of 0.00001. Use initial guesses \( x = 0, y = 0, z = 0 \). Input the augmented matrix (coefficients and constants) in a single array.

Solve the following system of linear equations

\( 4x - y + z = 15 \)

\( -x + 4y - z = 10 \)

\( 2x - y + 3z = 10 \)

Theoretical Background & Computational Mechanics

Algorithm:

Initial Guess:

Start with an initial guess for the unknowns (in this case, \( x = y = z = 0 \)).

Iteratively Solve for Each Variable:

Use the current or updated values of the variables as soon as they are available.

From the system:

\( x^{(k+1)} = \frac{1}{4} (15 + y^{(k)} - z^{(k)}) \)

\( y^{(k+1)} = \frac{1}{4} (10 + x^{(k+1)} + z^{(k)}) \)

\( z^{(k+1)} = \frac{1}{3} (10 - 2x^{(k+1)} + y^{(k+1)}) \)

Convergence Check:

Stop when the difference between consecutive values of \( x \), \( y \), and \( z \) is less than a predefined tolerance (e.g., \( 10^{-5} \)).

Program 2

Gauss-Seidel Method

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

Gauss-Seidel Iterative Method Problem

Solve the following system of linear equations using the Gauss-Seidel method:

\[ \begin{cases} 10x_1 - x_2 + 2x_3 = 6 \\ -x_1 + 11x_2 - x_3 + 3x_4 = 25 \\ 2x_1 - x_2 + 10x_3 - x_4 = -11 \\ 3x_2 - x_3 + 8x_4 - 2x_5 = 15 \\ -2x_4 + 6x_5 = 10 \end{cases} \]

Use the following specifications for the iterative solution:

  • Initial guess: \(x_1 = x_2 = x_3 = x_4 = x_5 = 0\)
  • Convergence tolerance: \(10^{-5}\)
  • Maximum iterations: 1000

Compute the solution vector \(\mathbf{x} = [x_1, x_2, x_3, x_4, x_5]^T\) using the Gauss-Seidel iteration and verify it using a direct solver.

Algorithm:

  • A = Coefficient matrix
  • B = Right-hand side constants
  • We start with all zeros as initial guesses.
  • For each iteration:
    • Each unknown is updated using the latest available values.
    • The formula used is:

    \( x_i = \frac{B_i - \sum_{j \neq i} a_{ij} x_j}{a_{ii}} \)

  • The process repeats until the change is smaller than the tolerance.
  • Program 3

    Gauss-Seidel Method

    Python 3.11 Ready
    
                                    
    Click "Run Code" to execute script and render figures.

    Mathematical Problem Formulation

    Gauss-Seidel Iterative Method Problem

    Solve the following system of linear equations using the Gauss-Seidel method:

    \[ \begin{cases} 10x_1 - x_2 + 2x_3 = 6 \\ -x_1 + 11x_2 - x_3 + 3x_4 = 25 \\ 2x_1 - x_2 + 10x_3 - x_4 = -11 \\ 3x_2 - x_3 + 8x_4 - 2x_5 = 15 \\ -2x_4 + 6x_5 = 10 \end{cases} \]

    Use the following specifications for the iterative solution:

    • Initial guess: \(x_1 = x_2 = x_3 = x_4 = x_5 = 0\)
    • Convergence tolerance: \(10^{-5}\)
    • Maximum iterations: 1000

    Compute the solution vector \(\mathbf{x} = [x_1, x_2, x_3, x_4, x_5]^T\) using the Gauss-Seidel iteration and verify it using a direct solver.

    Alternate Method using Numpy Array Slice.

    Theoretical Principles & Computational Physics Guide

    Gauss-Seidel Method: Matrix Formulation & Linear Algebraic Methods

    Dr. Alorika Chatterjee & Dr. Anirban Shaw Science & Physics Learners Python 3 / NumPy / SciPy

    1. Core Principles & Theoretical Framework

    Linear Transformation: Matrices represent multi-variable coupled physical equations, rotation operators, and quantum observables.
    Coordinate Transformations: Maps physical state vectors $\mathbf{x} \mapsto \mathbf{A}\mathbf{x}$ preserving or scaling metric spaces.
    Numerical Stability: Employs pivoting and condition number monitoring to avoid numerical singularity during inversion.

    2. Mathematical Formulation & Algorithmic Pipeline

    Linear algebraic operator transformation:

    $$ \mathbf{A}\mathbf{x} = \mathbf{b} \iff \sum_{j=1}^n A_{ij} x_j = b_i, \quad \det(\mathbf{A}) \neq 0 $$
    1. Construct Matrix/Vector → 2. Linear Operator Execution → 3. Verify Norm / Residual $\|\mathbf{A}\mathbf{x} - \mathbf{b}\|$

    3. Numerical Mechanics & Implementation Logic

    • Memory Layout: Structure row and column arrays ensuring dimensional conformability.
    • Algorithmic Execution: Apply row operations or inner product contractions iteratively.
    • Condition Checking: Verify determinant or diagonal dominance to guarantee reliable numerical convergence.

    4. Relevant Computational Practice Exercises

    Exercise 1
    Implement Gauss-Seidel Method for a $3 \times 3$ system and verify the result against analytical solutions.
    Exercise 2
    Measure the computational scaling of the algorithm as matrix dimension $N$ increases from $10$ to $100$.
    Exercise 3
    Test edge cases involving singular or ill-conditioned matrices and handle potential division-by-zero errors.
    Standard Literature & References:
    • Gilbert Strang, "Linear Algebra and Its Applications", Cengage Learning (2006).
    • William H. Press et al., "Numerical Recipes", Cambridge University Press (2007).