ES 204 L2 Linear Equations
ES 204 L2 Linear Equations
ä The admission fee at a small fair is 1.50 for children and 4.00
for adults. On a certain day, 2200 people enter the fair and 5050 is
collected. How many children and how many adults attended?
Answer: 1500 children and 700 adults
y = Ax2 + Bx + C
9 = A(−1)2 + B(−1) + C
5 = A(1)2 + B(1) + C
12 = A(2)2 + B(2) + C
Answer: y = 3x2 − 2x + 4
a1 x1 + a2 x2 + . . . + an xn = b
System
r = [rj ] = [r1 r2 · · · rn ]
ä Column vector,
c1
c2
c = [ci ] =
..
.
cm
ä Recall basic matrix operations
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 9 / 75
Matrix Equation
ä Steps:
1 Transform the matrix of coefficients into upper triangular
matrix using row operations
2 Backsubstitution
ä Augmented matrix
2 4 −2 2 2 4 −2 2
4 9 −3 8 ⇒ 0 1 1 4 R2 = R2 − 42 R1
−2 −3 7 10 0 1 5 12 R3 = R3 − −2
2 R1
2 4 −2 2
⇒ 0
1 1 4
0 0 4 8 R3 = R3 − 11 R2
ä Equivalent matrix
2 4 −2 x1 2
0 1 1 x2 = 4
0 0 4 x3 8
ä Backsubstitution
1 Row 3: 4x3 = 8 =⇒ x3 = 8/4 = 2
2 Row 2: x2 + x3 = 4 =⇒ x2 = 4 − 2 = 2
3 Row 1:
2x1 + 4x2 − 2x3 = 2 =⇒ x1 = (2 − 4 × 2 + 2 × 2)/2 = −1
ä Solution
x1 −1
x2 = 2
x3 2
ä Row pivoting - let row k be pivot row with pivot element akk
0 1 2 3 x1 −0.2
0 1 4 12 x2 0.8
1 1 1 1 x3 = 1.5
1 2 4 8 x4 1.2
ä First pass
1 1 1 1 1.5
0 1 4 12 0.8
0 1 2 3 −0.2
0 1 3 7 −0.3 R4 = R4 − 11 R1
ä Second pass
1 1 1 1 1.5
0 1 4 12 0.8
0 0 −2 −9 −1.0 R3 = R3 − 11 R2
0 0 −1 −5 −1.1 R4 = R4 − 11 R2
ä Third pass
1 1 1 1 1.5
0 1 4 12 0.8
0 0 -2 −9 −1.0
−1
0 0 0 −0.5 −0.6 R4 = R4 − −2 R3
ä Solution
x1 −0.8
x2 6.0
x3 = −4.9
x4 1.2
ä No solution
1 1 1 −1 1 1 1 −1
2 2 5 −8 ⇒ 0 0 3 −6
4 4 8 −14 0 0 4 −10
2 −5 4 8 −1 −2 1 2
2 0 2 4 ⇒ 0 1 0 −4
−1 −2 1 2 0 0 0 8
ä Infinite solutions
1 1 1 −1 1 1 1 −1
2 2 5 −8 → 0 0 3 −6
4 4 8 −12 0 0 4 −8
x1 + x2 = 1 x3 = −2
ä Transform to D · x = b (D is diagonal)
0 1 2 3 −0.2
0 1 4 12 0.8
1 1 1 1 1.5
1 2 4 8 1.2
ä First row pivot
1 1 1 1 1.5
0 1 4 12 0.8
0 1 2 3 −0.2
0 1 3 7 −0.3 R4 = R4 − (1)R1
ä Second row pivot
0 −3 −11
1 0.7 R1 = R1 − (1)R2
0 1 4 12 0.8
0 0 −2 −9 −1.0 R3 = R3 − (1)R2
0 0 −1 −5 −1.1 R4 = R4 − (1)R2
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 21 / 75
Gauss-Jordan
0 −3 −11
1 0.7
0 1 4 12 0.8
0 0 1 4.5 0.5
0 0 −1 −5 −1.1
0 −0.8
1 0 0 R1 = R1 − (2.5)R4
0
1 0 0 6.0 R2 = R2 − (−6)R4
0 0 1 0 −4.9 R3 = R3 − (4.5)R4
0 0 0 1 1.2
ä Final matrix
1 0 0 0 x1 −0.8
0 1 0 0 x2
6.0
=
0 0 1 0 x3 −4.9
0 0 0 1 x4 1.2
ä Solution
−0.8
6.0
xi =
−4.9
1.2
ä LU decomposition
1 Set up A · x = b
2 Determine L and U → LU · x = b
Row operations only
No row swapping
Leading ones not necessary
LU decomposition is not unique
3 Let U · x = y then solve for y from L · y = b
4 Solve for x from U · x = y
5 x is also the solution of A · x = b
ä Solve
x1 + 2x2 + 3x3 = 5
2x1 − 4x2 + 6x3 = 18
3x1 − 9x2 − 3x3 = 6
ä Solution
1 2 3 x1 5
2 −4 6 x2 = 18
3 −9 −3 x3 6
1 2 3 1 0 0 1 2 3
2 −4 6 → L = 2 −8 0 U = 0 1 0
3 −9 −3 3 −15 −12 0 0 1
ä L·y =b
1 0 0 y1 5
2 −8 0 y2 = 18
3 −15 −12 y3 6
5
yi = −1
2
ä U·x=y
1 2 3 x1 5
0 1 0 x2 = −1
0 0 1 x3 2
1
xi = −1
2
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 29 / 75
Outline
1 Linear Equations
Matrix
Matrix Equation
2 An Illustration
3 Techniques
Gaussian Elimination
LU Decomposition
Jacobi Iteration
Gauss-Seidel Method
SOR
SSOR
Line Search Method
Steepest Descent
Conjugate Gradient
Others
4 Vector Norms
5 Credits
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 30 / 75
Jacobi Iteration
ä The system
ä Solve the first equation for x1 , then second for x2 and so on.
1
x1 = (b1 − a12 x2 − a13 x3 − · · · − a1n xn )
a11
1
x2 = (b2 − a21 x1 − a23 x3 − · · · − a2n xn )
a22
..
.
1
xn = (bn − an1 x1 − an3 x3 − · · · − an,n−1 xn−1 )
ann
has a unique solution.
ä Approximate initial values of xi then solve for new values of xi .
x1
xi = ...
xn
ä Repeat replacing old xi with new xi until exit criterion is
satisfied.
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 32 / 75
Jacobi Iteration
ä Solve
ä First pass
x1 = − 15 + 25 (0) − 53 (0) = −0.200
2 3 1
x2 = 9 + 9 (0) − 9 (0) ≈ 0.222
3
x3 = − 7 + 7 (0) − 71 (0) ≈ −0.429
2
ä Answer
0.186
xi = 0.331
−0.423
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 34 / 75
Outline
1 Linear Equations
Matrix
Matrix Equation
2 An Illustration
3 Techniques
Gaussian Elimination
LU Decomposition
Jacobi Iteration
Gauss-Seidel Method
SOR
SSOR
Line Search Method
Steepest Descent
Conjugate Gradient
Others
4 Vector Norms
5 Credits
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 35 / 75
Gauss-Seidel Method
ä Jacobi: 7, Gauss-Seidel: 5
x1 − 5x2 = −4
7x1 − x2 = 6
ä Solution
x1 = −4 + 5x2
x2 = −6 + 7x1
ä Gauss-Seidel
n 0 1 2 3 4 5
x1 0 −4 −174 −6124 −214374 −7503124
x2 0 −34 −1244 −42874 −1500624 −52521874
ä Rearrange
6
x1 = 7 + 17 x2
4
x2 = 5 + 15 x1
ä Initial approximation, (x1 , x2 ) = (0, 0)
n 0 1 2 3 4 5
x1 0.000 0.8571 0.9959 0.9999 1.000 1.000
x2 0.000 0.9714 0.9992 1.000 1.000 1.000
ä For A · x = b
ä Jacobi Iteration
(k+1) 1 X (k)
xi = bi − aij xj
aii
j6=i
or
(k+1)
xi = D−1 (L + U)x(k) + D−1 b
ä Gauss-Seidel Method
i−1 n
(k+1) 1 X (k+1)
X (k)
xi = bi − aij xj − aij xj
aii
j=1 j=i+1
or
(k+1)
xi = (D − L)−1 (Ux(k) + b)
where the matrices D, -L, and -U represent the diagonal, strictly
lower triangular, and strictly upper triangular parts of matrix A
respectively.
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 43 / 75
Symmetric Positive Definite
A = AT
and
xT Ax > 0, all x 6= 0
then we say that A is symmetric positive definite or A ∈ SPD.
Another way of putting it,
ä Cholesky Theorem
Let A ∈ Rn×n be given, with A ∈ SPD. Then
1. A is nonsingular.
2. There exists a lower triangular matrix G ∈ Rn×n , with gii > 0,
such that GGT = A.
Copyright c 2020 M. Vasquez, University of the Philippines. All rights reserved. 44 / 75
Norm and Spectral Radius
ä Norm
Let A ∈ Rn×n be given. Define T = M−1 N, where A = M − N
(splitting method). Then the iteration
converges for all initial guesses x(0) if and only if there exists a
norm k · k such that kTk < 1.
ρ(A) = max|λ|
ä For A · x = b
ä If A is symmetric positive definite, then 0 < ω < 2 is the
sufficient condition for convergence.
i−1 n
(k+1) 1 X (k+1)
X (k)
xi = bi − aij xj − aij xj
aii
j=1 j=i+1
ä Example
−4 1 1 1 x1 1
1 −4 1 1 x2 1
=
1 1 −4 1 x3 1
1 1 1 −4 x4 1
ω Iterations ω Iterations
1.0 24 ← Gauss-Seidel 1.5 18
1.1 18 1.6 24
1.2 13 1.7 35
1.3 11 ← Optimum 1.8 55
1.4 14 1.9 100
ä “Optimal” ω
The “best” value of ω for the SOR iteration (“best” in the sense
that it leads to the smallest spectral radius for the SOR iteration
matrix) is given by
2
ω= p
1 + 1 − ρ2 (A)
where
Backward SOR Sweep: B1 = (D + ωU)−1 (−ωL + (1 − ω) D)
Forward SOR Sweep: B2 = (D + ωL)−1 (−ωU + (1 − ω) D)
xT Ax > 0
ä Quadratic equation
1
ϕ(x) = xT Ax − bT x
2
ä Choose an initial position x0 and for each step walk along a
direction (line) so that ϕ(x(k+1) ) ≤ ϕ(x(k) )
ä Quadratic form
1
ϕ(x) = xT Ax − bT x + c
2
Gradient of the quadratic form,
∂
∂x1 ϕ(x)
∂
ϕ(x)
0
ϕ (x) = ∂x
2.
..
∂
ϕ(x)
∂xn
If A is symmetric,
ϕ0 (x) = A · x − b
Setting the gradient to zero then,
A·x=b
ä Residual
r(k) = b − A · x(k)
Note: If r(k) = 0 then x(k) is a solution.
ä Solve for α
r(k)T r(k)
α(k) = (k)T (k)
r Ar
ä Update x
x(k+1) = x(k) + α(k) r(k)
Example:
3 2 2
A= , b= , c=0
2 6 −8
Initialize:
1
x0 =
−1
Iteration no. 1:
r1 = b − A · x0
2 3 2 1 1
r1 = − · =
−8 2 6 −1 −4
1
1 −4
r1T r1 −4 17
α1 = T = = = 0.204819
r1 Ar1 3 2 1 83
1 −4
2 6 −4
1 1 1.205
x1 = x0 + α1 r1 = + 0.204819 =
−1 −4 −1.819
Iteration no. 2:
r2 = b − A · x0
2 3 2 1.205 2.023
r2 = − · =
−8 2 6 −1.819 0.504
2.023
2.023 0.504
rT r2 0.504 4.347
α2 = T2 = = = 0.243120
r2 Ar2 3 2 2.023 17.880
2.023 0.504
2 6 0.504
1.205 2.023 1.697
x2 = x1 + α2 r2 = + 0.243120 =
−1.819 0.504 −1.806
Iteration 0 1 2 3 4 5 6
x1 1 1.205 1.697 1.921 1.964 1.988 1.989
x2 -1 -1.819 -1.806 -2.02 -1.977 -2.002 -2.001
ä Initialize
r0 = b − A · x0 = p0
ä Search α(k) along p(k)
r(k)T p(k)
α(k) =
p(k)T Ap(k)
ä Update x and r
r(k+1)T Ap(k)
β (k) = − ; p(k+1) = r(k+1) + β (k) p(k)
p(k)T Ap(k)
ä Cramer’s rule
ä Minimum Residual
ä Biconjugate gradient
ä Tridiagonal matrix
n
!1
X p
kxkp = |xi |p , p ≥ 1,
i=1
ä Example:
Consider the vector x = (3, −1, 2, 0, 4) which belongs to the vector
space R5 .
L1 : kxk1 = |3| + | − 1| + |2| + |0| + |4| = 10.
p √
L2 : kxk2 = |3|2 + | − 1|2 + |2|2 + |0|2 + |4|2 = 30