Direct Methods
Direct Methods
Direct Methods
MTL 107
Harish Kumar
(hkumar@iitd.ac.in)
x1
▶ Find x =
x2
which satisfies
a11 x1 + a12 x2 = b1
a21 x1 + a22 x2 = b2
or,
Ax = b
a11 a12
where A =
a21 a22
umerical Methods for Computational Science and Engineering
Basic concepts: linear system of equations
Basic concepts: linear system of equations (cont.)
Basic concepts: linear system of equations (cont.)
Solving a 2 × 2 system.
I Unique solution if and only if lines are not parallel.
We can write Ax = b as
a1 x1 + a2 x2 + · · · + an xn = b
1 1
A=
3 3
1
null(A) = α , α ∈ R,
−1
1
range(A) = β , β ∈ R.
3
2
Give all solutions of Ax = b with b= .
6
Example (Almost singularity)
Let’s
look atlinear
system
of equations
1+ε 1 x1 2+ε
= where 0 < ε ≪ 1.
3 3 x2 6
1
The unique solution is x= .
1
System matrix above is almost singular, i.e., a small perturbation
makes it singular.
The close-by problem has many solutions, some are far apart from
x: ill-conditioned problem.
Vector norms
whenever Q ⊤ Q = I .
Matrix norms (cont.)
The last identity comes from the observation that the vector x
which maximizes the supremum is given by x = (±1, ±1, · · · , ±1)⊤
with the sign of the entries chosen according to the sign of the
entries in the row of A with the largest row sum.
Matrix norms (cont.)
u⊤ v = 0
Q ⊤Q = I Hence, also Q −1 = Q ⊤ .
∥Qx∥2 = ∥x∥2
Hence,
∥Q∥2 = Q −1 2
= 1.
Linear systems: Problem statement
or,
Ax = b
The matrix elements aik and the right-hand side elements bi are
given. We are looking for the unknowns xk .
Direct vs. iterative methods
Ax = b
A is given, real, nonsingular, n × n and b is real, given vector.
Such problems are ubiquitous!
Two types of solution approaches:
1. Direct method: yield exact solution in absence of roundoff
error.
▶ Variations of Gaussian elimination.
2. Iterative method: iterate in a similar fashion to what we do
for nonlinear problems.
▶ Use only when direct methods are ineffective.
Existence and uniqueness of LU decomposition
Theorem
If A is nonsingular, then one can find a row permutation P such
that PA satisfies the conditions of the previous theorem, that is PA
= LU exists and is unique.
Gaussian elimination for Ax = b
x1 x2 x3 x4 1
a11 a12 a13 a14 b1
a21 a22 a23 a24 b2
a31 a32 a33 a34 b3
a41 a42 a43 a44 b4
x1 x2 x3 x4 1
a11 a12 a13 a14 b1
0 ′
a22 ′
a23 ′
a24 b2′
0 ′
a32 ′
a33 ′
a34 b3′
0 ′
a42 ′
a43 ′
a44 b4′
′ ̸= 0.
1. Permute rows i = 2, ..., 4 (if necessary) such that a22
This is next pivot.
′ = a′ /a′ of row 2 from row i,
2. Subtract multiples li2 i2 22
i = 3, · · · , 4.
′′ = a′ − l ′ a′ , k, i = 3, · · · , 4
3. Set aik ik i2 2k
4. Set bi′′ = bi′ − li2
′ b ′ , i = 3, · · · , 4
2
Gaussian elimination for Ax = b (cont.)
x1 x2 x3 x4 1
a11 a12 a13 a14 b1
0 ′
a22 ′
a23 ′
a24 b2′
0 0 ′
a33 ′
a34 b3′
0 0 ′
a43 ′
a44 b4′
′′ ̸= 0.
1. Permute rows i = 3, ..., 4 (if necessary) such that a33
This is the next pivot.
′′ = a′′ /a′′ of row 3 from row 4.
2. Subtract multiples l43 43 33
′′′ = a′′ − l ′′ a′′ ,
3. Set a44 44 43 34
4. Set b4′′′ = b4′′ − li1
′′ b ′′ .
3
Gaussian elimination for Ax = b (cont.)
x1 x2 x3 x4 1 x1 x2 x3 x4 1
u11 u12 u13 u14 c1 a11 a12 a13 a14 b1
0 u22 u23 u24 c2 ⇐⇒ 0 ′
a22 ′
a23 ′
a24 b2′
0 0 u33 u34 c3 0 0 ′
a33 ′
a34 b3′
0 0 0 u44 c4 0 0 0 ′
a44 b4′
x1 x2 x3 x4 1
a11 a12 a13 a14 b1
l21 ′
a22 ′
a23 ′
a24 b2′
l31 ′
l32 ′′
a33 ′′
a34 b3′′
l41 ′
l42 ′
l43 ′′′
a44 b4′′′
U = L−1 −1 −1
3 P3 L2 P2 L1 PA
U = L−1 −1 −1 −1 −1 −1
3 (P3 L2 P3 )(P3 P2 L1 P2 P3 )(P3 P2 P1 )A
LU = PA.
Since
det(A) = det(P −1 ) det(L) det(U)
and
det(L) = 1,
and
det(P −1 ) = det(P) = (−1)V
where V is the number of row permutations in the Gaussian
elimination, we have
n
Y
det(A) = (−1)V uii
i=1
1 for k=1:n-1
2 for i=k+1:n
3 l(i,k) = a(i,k)/a(k,k);
4 for j=k+1:n
5 a(i,j) = a(i,j) - l(i,k)*a(k,j);
6 end
7 end
8 end
Complexity: LU factorization
1 1
= n(n − 1) + n(n − 1)(2n − 1)
2 3
2 3 1 2 1
= n − n − n
3 2 6
2
= n3 + O(n2 )
3
Algorithm: forward and Backward substitution
LU = PA
0 1 x1 4
Ax=b ⇐⇒ =
1 1 x2 7
x1 x2 1
0 1 4
1 1 7
x1 x2 1
1 1 7
0 1 4
Need for pivoting (cont.)
x1 x2 1
0.00035 1.2654 3.5267
1.2547 1.3182 6.8541
x1 x2 1
→ 0.00035 1.2654 3.5267 with
0 -4535.0 -12636
Backsubstitution gives
x2 = −12636/(−4535.0) ≈ 2.7863
x1 = 2.5354, x2 = 2.7863
k−1 (k−1)
apk = max aik
i≥k
x1 x2 1
→ 1.2547 1.3182 6.8541 with
0 1.2650 3.5248
l21 = 0.00027895
x2 = 2.7864
x1 = (6.8541−1.3182×2.7864)/1.2547 ≈ 3.1811/1.2547 ≈ 2.5353
There is a deviation from the exact solution in the last digit only.
GEPP stability
1,
if i = j or j = n,
n
An = (aij )i,j=1 with −1 if i > j,
0 otherwise.
1 0 0 0 0 1
−1
1 0 0 0 1
−1 −1 1 0 0 1
A6 =
−1
−1 −1 1 0 1
−1 −1 −1 −1 1 1
−1 −1 −1 −1 −1 1
Partial Pivoting do not trigger change of row and last column
grows.
Complete pivoting
Definition
A matrix A ∈ Rn×n is diagonally dominant, if
X
|aii | ≥ |aik | , i = 1, ..., n.
k̸=i
Theorem
If A is nonsingular and diagonally dominant then the LU
factorization can be computed without pivoting.
Proof
We show that after reduction of the first row, the reduced system
is again diagonally dominant. We have
(1) ai1 a1k
aik = aik − , i, k = 2, ..., n.
a11
For the diagonal elements we get the estimate
ai1
≤ |aii | − |ai1 | + {|a11 | − |a1i |}
a11
ai1 a1i (1)
= |aii | − ≤ aii .
a11
Lecture 11
Cholesky Decomposition, Linear Algebra Libraries and Matlab
routine
Symmetric, positive definite systems
Definition
A symmetric matrix A is positive definite, if the corresponding
quadratic form is positive definite, i.e., if
Theorem
If a symmetric matrix A ∈ Rn×n is positive definite, then the
following conditions hold.
1. aii > 0 for i=1,...,n.
2 <a a
2. aik ii kk for i ̸= k, i, k = 1, ..., n.
3. There is a k with maxi,k |aik | = akk .
Proof.
1. aii = e⊤
i Aei > 0.
2. (ξei + ek )⊤ A(ξei + ek ) = aii ξ 2 + 2aik ξ + akk > 0.This
quadratic equation has no real zero ξ, therefore its
2 − 4a a
discriminant 4aik ii kk must be negative.
3. Clear.
Gaussian elimination works w/o pivoting. Since a11 > 0 we have
a11 a⊤ 0⊤ a⊤
1 1 a11 1
A= =
a1 A1 a1 /a11 I 0 A1 − a1 a⊤ 1 /a11
0⊤ a11 0⊤ 1 a⊤
=
1 1 /a11
a1 /a11 I 0 A(1) 0 I
with A(1) = A1 − a1 a⊤
1 /a11 . But for any x ∈ R
n−1 /{0} we have
⊤
a11 0⊤
0 0
x⊤ A(1) x =
x 0 A(1) x
⊤
0⊤ a11 a⊤ 1 −a⊤
0 1 1 1 /a11 0
=
x −a1 /a11 I a1 A1 0 I x
= y⊤ Ay > 0.
Cholesky decomposition
Lc = b (Forward substitution)
L⊤ x = c (Backward substitution)
The complexity is half that of the LU factorization:
1 3
n + O(n2 )
3
Efficient implementation
See http://www.netlib.org/blas
BLAS-1: vector operations (real, double, complex variants)
▶ Swap two vectors, copy two vectors, scale a vector
▶ AXPY operation: y = αx + y
▶ 2-norm, 1-norm, dot product
▶ I AMAX index of largest matrix element:
first i such that |xi | ≥ |xk | for all k.
▶ O(1) flops per Byte memory access.
BLAS (cont.)
Let
1.2969 0.8648 0.8642
A= , b=
0.2161 0.1441 0.1440
Suppose somebody came up with the approximate solution
0.9911
x̃ =
−0.4870
−10−8
Then, r̃ = b − Ax̃ = =⇒ ∥r̃∥∞ = 10−8
10−8
2
Since x = =⇒ error ∥z̃∥∞ = 1.513 which is ≈ 108
−2
times larger than the residual.
Error estimation (cont.)
Definition
The quantity
κ(A) = ∥A∥ A−1
is called the condition number of A.
The condition number is at least 1:
∥E ∥2 1
=
∥A∥2 κ2 (A)
Error estimation (cont.)
This yields
A−1 ∞
= 1.513×108 =⇒ κ∞ (A) = 2.162×1.513×108 ≈ 3.27×108 .
1.513 3.27
The numbers 2 < 0.8642 confirm the estimate
∥z∥∞ ∥r̃∥∞
≤ κ∞ (A)
∥x∥∞ ∥b∥∞
Error estimation (cont.)
So, indeed,
∥E ∥ 1
≈ .
∥A∥ κ(A)
(This estimate holds in l2 and l∞ norms.)
Sensitivity on matrix coefficients
Thus,
δx = A−1 (δb − δAx − δAδx)
For compatible norms we have
Therefore, we have
A−1
∥δx∥ ∥δb∥
≤ + ∥δA∥
∥x∥ 1 − ∥A−1 ∥ ∥δA∥ ∥x∥
Sensitivity on matrix coefficients (cont.)
∥δb∥ ∥δA∥
≤ 5.10−d , ≤ 5.10−d .
∥b∥ ∥A∥
∥δx∥
≤ 10α−d+1
∥x∥
Rule of thumb (cont.)
x = D2 y.
Example
10 100000 x1 100000
=
1 1 x2 2
The row equivalent scaled problem is
0.0001 1 x1 1
=
1 1 x2 2
The solutions with 3 decimal digits are x̃ = (0, 1.00)T for the
unscaled system and x̃ = (1.00, 1.00)T for the scaled system.
The correct solution is x = (1.0001, 0.9999)T .
See Example 5.11 in Ascher and Greif
Theorem on scaling
Theorem
Let A ∈ Rn×n be nonsingular. Let the diagonal matrix Dz be
defined by
−1
n
X
dii = |aij |
j=1
Then
κ∞ (Dz A) ≤ κ∞ (DA)
for all nonsingular diagonal D.
See: Dahmen & Reusken: Numerik fur Ingenieure und
Naturwissenschaftler. 2nd ed. Springer 2008.
Remark on determinants