2 - Systems of Linear Equations (older version)

2 - Systems of Linear Equations (older version)

Updated 14 Oct 2026

Key Concepts & Overview

Analytical vs Numerical Methods

  • Analytical methods: Work with arbitrary data, produce closed-form solutions exactly
  • Numerical methods: Work only with concrete numbers, sequence of operations depends on actual values
  • Focus: Computer-based solving (numerical) vs hand solving (analytical)
  • Many problems can't be solved analytically or are too slow to be practical

Block Matrix Notation

Partitioning matrices into smaller submatrices

ถ้ามาจาก same horizontal line จะมี the same number of column
ถ้ามาจาก same vertical line จะมี the same number of rows

  • Example: [ABCD]\begin{bmatrix} A & B \\ C & D \end{bmatrix} where dimensions are compatible
  • Operations work like normal matrices: (A+E,B+F;C+G,D+H)(A + E, B + F; C + G, D + H) for addition
  • Multiplication: [AE+BGAF+BHCE+DGCF+DH]\begin{bmatrix} AE + BG & AF + BH \\ CE + DG & CF + DH \end{bmatrix}

Linear System Fundamentals

Standard Form

  • Problem: Find x1,x2,…,xnx_1, x_2, \ldots, x_n such that: a11x1+a12x2+⋯+a1nxn=b1a_{11}x_1 + a_{12}x_2 + \cdots + a_{1n}x_n = b_1 a21x1+a22x2+⋯+a2nxn=b2a_{21}x_1 + a_{22}x_2 + \cdots + a_{2n}x_n = b_2 ⋮\vdots an1x1+an2x2+⋯+annxn=bna_{n1}x_1 + a_{n2}x_2 + \cdots + a_{nn}x_n = b_n
  • Matrix form: Ax=bAx = b where A∈Rn×nA \in \mathbb{R}^{n \times n}, x,b∈Rnx, b \in \mathbb{R}^n

Solution Existence

  • If A is nonsingular: A−1A^{-1} exists, unique solution x=A−1bx = A^{-1}b
  • If A is singular: Either no solutions or infinitely many solutions (depends on bb)

Triangular Systems

Lower Triangular Matrices

  • Definition: Lij=0L_{ij} = 0 for i<ji < j (entries above main diagonal are zero)
  • Forward Substitution Formula: xi=(bi−∑j=1i−1lijxj)/lii,i=1,…,nx_i = \left(b_i - \sum_{j=1}^{i-1} l_{ij}x_j\right) / l_{ii}, \quad i = 1, \ldots, n
  • Note that ∑j=10liixj=0\sum_{j=1}^0 l_{ii}x_j=0 by convention.

Theorem


A square upper or lower triangular matrix is nonsingular if and only if all of its diagonal entries are nonzeros.

Upper Triangular Matrices

  • Definition: Uij=0U_{ij} = 0 for i>ji > j (entries below main diagonal are zero)
  • Back Substitution Formula: xi=(bi−∑j=i+1nuijxj)/uii,i=n,…,1x_i = \left(b_i - \sum_{j=i+1}^{n} u_{ij}x_j\right) / u_{ii}, \quad i = n, \ldots, 1

Key Theorem

  • A square triangular matrix is nonsingular iff all diagonal entries are nonzero

Algorithm Versions

  • Version 1: Row-oriented (sequential inner loop)
  • Version 2: Column-oriented (better concurrency, can parallelize inner loop)
  • Running Time: Both versions are O(n2)O(n^2)

Gaussian Elimination & LU Factorization

Basic Gaussian Elimination

เวลาเปลี่ยนก็ต้องมั่นใจว่าไม่ได้เปลี่ยน Solution

  • Goal: Transform AA into upper triangular matrix UU
  • Process: Eliminate entries below main diagonal, column by column
  • Elimination Step: (Rowi):=(Rowi)−aikakk⋅(Rowk)(Row_i) := (Row_i) - \frac{a_{ik}}{a_{kk}} \cdot (Row_k)
  • Terminology:
    • akka_{kk} = pivot
    • aikakk\frac{a_{ik}}{a_{kk}} = multiplier

จริง ๆ เราทำเองก็ได้ แต่ว่ามันเป็นสูตรเพื่อให้มั่นใจ (ถ้าทำตาม) เดี๋ยวมันก็จะได้เป็น Upper triangular matrix เองเลยล่ะ!!

LU Factorization Theorem

แล้วถ้าจะ Construct LU บ้างล่ะ ข้างบนเป็น UT ไปแล้วใช่มะ

  • Result: A=LUA = LU where:
    • LL = unit lower triangular (ones on diagonal, multipliers below)
    • UU = upper triangular matrix from GE
  • L Construction:
    • Zeros above diagonal
    • Ones on diagonal
    • Multipliers used in elimination below diagonal

Three-Step Solution Procedure

  1. Factor: A=LUA = LU
  2. Forward substitution: Solve Lw=bLw = b for ww
  3. Back substitution: Solve Ux=wUx = w for xx
  • Verification: Ax=(LU)x=L(Ux)=Lw=bAx = (LU)x = L(Ux) = Lw = b ✓

Advantages of LU Factorization

  • Multiple right-hand sides: Factor AA once, reuse for different bb vectors
  • Efficiency: Same O(n3)O(n^3) operations as direct GE, but more flexible

Gaussian Elimination with Partial Pivoting (GEPP)

Problem with Plain GE

  • Pivot akka_{kk} might be zero even when matrix is nonsingular
  • Solution: Pivoting (row exchanges)

อย่าง Plain GE จะได้ LU
Does GEPP compute a matrix factorization?

  • เฉลย alternating between swap and eliminating

Partial Pivoting Strategy

  • Before each elimination: Swap rows to bring largest absolute value to pivot position
  • Selection: p=arg⁡max⁡∣apk∣:p=k,k+1,…,np = \arg\max{|a_{pk}| : p = k, k+1, \ldots, n}
  • Process: Exchange rows kk and pp

GEPP Factorization

  • Result: PA=LUPA = LU or equivalently A=PTLUA = P^T LU
  • P: Permutation matrix encoding all row swaps
  • Key theorem: GEPP encounters zero pivot iff AA is singular

Four-Step Solution with GEPP

  1. Factor: A=PTLUA = P^T LU by GEPP
  2. Permute: Set b^=Pb\hat{b} = Pb
  3. Forward substitution: Solve Lw=b^Lw = \hat{b} for ww
  4. Back substitution: Solve Ux=wUx = w for xx

Permutation Matrices

  • Properties:
    • Square matrix with entries 0 or 1
    • Exactly one 1 per row and column
    • PAPA permutes rows of AA
    • APAP permutes columns of AA
    • P−1=PTP^{-1} = P^T (orthogonal)

Implementation Notes

  • Running time: Still O(n3)O(n^3) (pivoting adds O(n2)O(n^2) total)
  • Storage: Don't store PP explicitly, use vector of indices
  • Accuracy: Using max absolute value gives lowest error in floating-point

Computing Matrix Inverses

Method Using GEPP

  • Goal: Compute A−1A^{-1} where A∈Rn×nA \in \mathbb{R}^{n \times n}
  • Approach: Solve Axi=eiAx_i = e_i for i=1,…,ni = 1, \ldots, n
  • Reasoning: A[x1;x2;⋯ ;xn]=[e1;e2;⋯ ;en]=IA[x_1 ; x_2 ; \cdots ; x_n] = [e_1 ; e_2 ; \cdots ; e_n] = I
  • Efficiency: Factor A=PTLUA = P^T LU once, then solve nn systems

Important Best Practice

  • Never compute A−1vA^{-1}v explicitly!
  • Instead: Solve Ax=vAx = v for xx using GEPP
  • Reason: More accurate and faster than computing inverse then multiplying

MATLAB Implementation

  • Use A \ b not inv(A) * b
  • MATLAB automatically chooses optimal algorithm based on matrix structure

lu(A) ใน MATLAB จะเป็น GEPP เลยนะ not plain GE

Advanced Topics

Sherman-Morrison Formula

  • Problem: Solve (A−uvT)x=b(A - uv^T)x = b efficiently when A=PTLUA = P^T LU is known
  • Formula: (A−uvT)−1=A−1+A−1u(1−vTA−1u)−1vTA−1(A - uv^T)^{-1} = A^{-1} + A^{-1}u(1 - v^T A^{-1}u)^{-1}v^T A^{-1}
  • Algorithm (O(n2)O(n^2) operations):
    1. Solve Az=uAz = u for zz
    2. Solve Ay=bAy = b for yy
    3. Compute x=y+vTy1−vTzzx = y + \frac{v^T y}{1 - v^T z} z

Woodbury Formula

  • Generalization: (A−UVT)−1=A−1+A−1U(I−VTA−1U)−1VTA−1(A - UV^T)^{-1} = A^{-1} + A^{-1}U(I - V^T A^{-1}U)^{-1}V^T A^{-1}
  • Application: Rank-kk modifications where U,VU, V are n×kn \times k matrices

Existence of LU Factorization

  • Not guaranteed: Some matrices have no LU factorization
  • Example: [01 10]\begin{bmatrix} 0 & 1 \ 1 & 0 \end{bmatrix} has no LU factorization
  • Solution: Use pivoting (GEPP always works for nonsingular matrices)

MATLAB Commands Summary

Basic Operations

  • Solve system: x = A \ b
  • LU factorization: [L,U,P] = lu(A)
  • Matrix inverse: Ai = inv(A) (avoid when possible)

Advanced Usage

  • Vector form pivoting: [L,U,pvec] = lu(A, 'vector')
  • Multiple systems: Factor once, reuse for different right-hand sides
  • Documentation: help lu, doc mldivide for more details

Complexity Analysis

Operation Counts

  • LU factorization: O(n3)O(n^3) operations
  • Forward/back substitution: O(n2)O(n^2) operations each
  • Total for solving Ax=bAx = b: O(n3)O(n^3) operations
  • Multiple right-hand sides: O(n3)O(n^3) for factorization + O(n2)O(n^2) per additional solve