Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Outline
Scientific Computing: An Introductory Survey
1
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Scientific Computing
Michael T. Heath
1 / 88
Scientific Computing
2 / 88
det(A) 6= 0
rank(A) = n
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Scientific Computing
3 / 88
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Scientific Computing
4 / 88
Geometric Interpretation
In two dimensions, each equation determines straight line
in plane
b
arbitrary
b span(A)
b
/ span(A)
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
# solutions
one (unique)
infinitely many
none
Scientific Computing
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Example: Nonsingularity
Scientific Computing
6 / 88
Example: Singularity
2 2 system
2 2 system
2x1 + 3x2 = b1
5x1 + 4x2 = b2
Ax =
or in matrix-vector notation
2 3 x1
b
Ax =
= 1 =b
5 4 x2
b2
Scientific Computing
2 3 x1
b
= 1 =b
4 6 x2
b2
7 / 88
Michael T. Heath
Scientific Computing
8 / 88
Vector Norms
Pn
2-norm: kxk2 =
i=1 |xi |
Pn
2
i=1 |xi |
1/2
kxk1 = 2.8
Scientific Computing
9 / 88
Scientific Computing
10 / 88
kxk > 0 if x 6= 0
kxk = || kxk for any scalar
kx + yk kxk + kyk
kxk1 n kxk
Scientific Computing
(triangle inequality)
Michael T. Heath
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Equivalence of Norms
11 / 88
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Matrix Norms
Scientific Computing
12 / 88
Matrix Norms
Matrix norm corresponding to vector 1-norm is maximum
absolute column sum
kAk1 = max
n
X
|aij |
i=1
kAk = max
i
n
X
|aij |
j=1
Scientific Computing
13 / 88
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Scientific Computing
14 / 88
Condition Number
Condition number of square nonsingular matrix A is
defined by
cond(A) = kAk kA1 k
Since
kA + Bk kAk + kBk
kAk kA1 k =
kAxk
kAxk 1
max
min
x6=0 kxk
x6=0 kxk
Michael T. Heath
Scientific Computing
15 / 88
Michael T. Heath
Scientific Computing
16 / 88
max |di |
min |di |
Scientific Computing
17 / 88
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Scientific Computing
18 / 88
Error Bounds
Condition number yields error bound for computed solution
to linear system
be solution to
Let x be solution to Ax = b, and let x
= b + b
Ax
kzk
kA1 k
kyk
x, then
If x = x
= A(x + x) = Ax + Ax
b + b = A(x)
Scientific Computing
19 / 88
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Scientific Computing
20 / 88
kxk
kEk
cond(A)
kxk
kAk
If input data are accurate to machine precision, then bound
for relative error in solution x becomes
xk
kx
cond(A) mach
kxk
Computed solution loses about log10 (cond(A)) decimal
digits of accuracy relative to accuracy of input
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Scientific Computing
Scientific Computing
22 / 88
Residual
to linear system
Residual vector of approximate solution x
Ax = b is defined by
r = b Ax
Since
Michael T. Heath
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Scientific Computing
kxk
krk
cond(A)
kxk
kAk kxk
Michael T. Heath
Scientific Computing
24 / 88
Residual, continued
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
exactly satisfies
If computed solution x
To solve linear system, transform it into one whose solution
is same but easier to compute
=b
(A + E)x
then
kEk
krk
kAk kxk
kAk
Solution to M Ax = M b is given by
x = (M A)1 M b = A1 M 1 M b = A1 b
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
25 / 88
Example: Permutations
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
26 / 88
Note that P 1 = P T
Premultiplying both sides of system by permutation matrix,
P Ax = P b, reorders rows, but solution x is unchanged
x = (AD)1 b = D 1 A1 b
x = (AP )1 b = P 1 A1 b = P T (A1 b)
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
27 / 88
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
28 / 88
Triangular Matrices
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
29 / 88
Forward-Substitution
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Back-Substitution
i1
X
x1 = b1 /`11 , xi = bi
`ij xj / `ii , i = 2, . . . , n
n
X
xn = bn /unn , xi = bi
uij xj / uii , i = n 1, . . . , 1
j=1
for j = 1 to n
if `jj = 0 then stop
xj = bj /`jj
for i = j + 1 to n
bi = bi `ij xj
end
end
Michael T. Heath
30 / 88
j=i+1
Scientific Computing
31 / 88
for j = n to 1
if ujj = 0 then stop
xj = bj /ujj
for i = 1 to j 1
bi = bi uij xj
end
end
Michael T. Heath
Scientific Computing
32 / 88
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Elimination
To transform general linear system into triangular form, we
need to replace selected nonzero entries of matrix by
zeros
2 4 2 x1
2
0 1
1 x2 = 4
0 0
4
x3
8
If a1 6= 0, then
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
33 / 88
1
0 a1
a
= 1
a2 /a1 1 a2
0
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
34 / 88
1
0
0 0
a1
a1
.. . .
..
.. . .
.
. .
.
.
. .. .. ..
.
.
1
0 0
ak ak
Mk a =
0 mk+1 1 0 ak+1 = 0
.. . .
..
.. . .
. . .
.
.
. .. .. ..
.
.
0
mn 0 1
an
0
where mi = ai /ak , i = k + 1, . . . , n
Divisor ak , called pivot, must be nonzero
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
35 / 88
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
36 / 88
2
For a = 4,
2
1 0 0
2
2
M1 a = 2 1 0 4 = 0
1 0 1 2
0
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
and
37 / 88
Example, continued
L1 =
1 0 0
2 1 0 ,
=
1 0 1
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
38 / 88
L2 =
M21
1
0
0
1
0
= 0
0 1/2 1
and
1 0 0
M1 M2 = 2 1 0 ,
1 1/2 1
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Gaussian Elimination
Note that
M11
1 0 0
2
2
M2 a = 0 1 0 4 = 4
0 1/2 1
2
0
1
0
0
1
0
L1 L 2 = 2
1 1/2 1
Scientific Computing
39 / 88
Michael T. Heath
Scientific Computing
40 / 88
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
LU Factorization
Product Lk Lj is unit lower triangular if k < j, so
1
L = M 1 = M11 Mn1
= L1 Ln1
M Ax = M b
So we have
A = LU
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
41 / 88
LU Factorization, continued
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
42 / 88
2
4 2 x1
2
9 3 x2 = 8 = b
Ax = 4
2 3
7 x3
10
1 0 0
2
4 2
2 4 2
9 3 = 0 1
1 ,
M1 A = 2 1 0 4
1 0 1
2 3
7
0 1
5
1 0 0
2
2
M1 b = 2 1 0 8 = 4
1 0 1
10
12
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
43 / 88
Example, continued
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
44 / 88
Example, continued
We have reduced original system to equivalent upper
triangular system
2 4 2 x1
2
1 x2 = 4 = M b
Ux = 0 1
0 0
4
x3
8
1
0 0
2 4 2
2 4 2
1 0 0 1
1 = 0 1
1 = U ,
M2 M1 A = 0
0 1 1
0 1
5
0 0
4
1
0 0
2
2
1 0 4 = 4 = M b
M2 M1 b = 0
0 1 1
12
8
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
45 / 88
Example, continued
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
46 / 88
Row Interchanges
Gaussian elimination breaks down if leading diagonal entry
of remaining unreduced matrix is zero at any stage
1 0 0 1 0 0
1 0 0
2 1 0 0 1 0 =
2 1 0 = L
L1 L2 =
1 0 1 0 1 1
1 1 1
so that
2
4 2
1 0 0
2 4 2
4
9 3 =
2 1 0
0 1
1 = LU
A=
2 3
7
1 1 1
0 0
4
Michael T. Heath
Scientific Computing
47 / 88
Michael T. Heath
Scientific Computing
48 / 88
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Partial Pivoting
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
M = Mn1 Pn1 M1 P1
M 1
L=
is still triangular in general sense, but not
necessarily lower triangular
Alternatively, we can write
PA = LU
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Complete Pivoting
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
50 / 88
Example: Pivoting
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
0 1
1 0
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
52 / 88
Example, continued
in floating-point arithmetic
Thus,
1 0 1 1
1 1
LU =
=
1 0 1
1
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Pivoting, continued
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
54 / 88
Residual
for solution x
computed using
Residual r = b Ax
Gaussian elimination satisfies
krk
kEk
n2 mach
kAk kxk
kAk
Diagonally dominant
n
X
j = 1, . . . , n
i=1, i6=j
Michael T. Heath
Scientific Computing
Michael T. Heath
Scientific Computing
56 / 88
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Residual, continued
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
/ n mach
kAk kxk
kAk
which means Gaussian elimination with partial pivoting
yields small relative residual regardless of conditioning of
system
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
57 / 88
Example, continued
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
58 / 88
for
for
for
aij = aij (aik /akk )akj
end
end
end
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Uniqueness of LU Factorization
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
60 / 88
identity matrix, so L = L
Uniqueness is made explicit in LDU factorization
P A = LDU , with L unit lower triangular, U unit upper
triangular, and D diagonal
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
61 / 88
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
62 / 88
Scientific Computing
Scientific Computing
n3 ,
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Storage Management
Michael T. Heath
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
three times as
63 / 88
Michael T. Heath
Scientific Computing
64 / 88
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Gauss-Jordan Elimination
0
0
1
..
.
..
.
..
.
0
a1
0
.. .. ..
. .
.
0
ak1 0
0 ak
= ak
0
ak+1 0
.. .. ..
. . .
1
..
.
.
..
..
.
..
.
0
..
.
m1
..
.
0
..
.
1
0
0
..
.
mk1
1
mk+1
..
.
mn
an
where mi = ai /ak , i = 1, . . . , n
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
65 / 88
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
66 / 88
Sherman-Morrison Formula
Sometimes refactorization can be avoided even when
matrix does change
(A uv T )1 = A1 + A1 u(1 v T A1 u)1 v T A1
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
= A1 b + A1 u(1 v T A1 u)1 v T A1 b
Solve Az = u for z, so z = A u
Solve Ay = b for y, so y = A1 b
Compute x = y + ((v T y)/(1 v T z))z
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
68 / 88
0
u=
and v = 1
2
0
Michael T. Heath
Scientific Computing
2
4 2 x1
2
4
9 3 x2 = 8
2 1
7 x3
10
x = (A uv T )1 b
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Example, continued
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
70 / 88
3/2
1
1/2
z=
and y = 2
1/2
2
1
3/2
7
2
vT y
= 4
2
1/2
x=y+
z
=
+
1 vT z
1 1/2
2
1/2
0
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Scientific Computing
Michael T. Heath
Scientific Computing
72 / 88
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Example: Scaling
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Iterative Refinement
Given approximate solution x0 to linear system Ax = b,
compute residual
r0 = b Ax0
Linear system
1 0 x1
1
=
0 x2
x1 = x0 + z0
= (b r0 ) + r0 = b
Michael T. Heath
Scientific Computing
Triangular Systems
Gaussian Elimination
Updating Solutions
Improving Accuracy
Michael T. Heath
Scientific Computing
Symmetric Systems
Banded Systems
Iterative Methods
74 / 88
Examples include
Symmetric : A = AT , aij = aji for all i, j
Scientific Computing
75 / 88
Symmetric Systems
Banded Systems
Iterative Methods
for j = 1 to n
for k = 1 to j 1
for i = j to n
aij = aij aik ajk
end
end
ajj = ajj
for k = j + 1 to n
akj = akj /ajj
end
end
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
l22 =
2
a22 l21
Scientific Computing
77 / 88
Symmetric Systems
Banded Systems
Iterative Methods
Scientific Computing
Symmetric Systems
Banded Systems
Iterative Methods
78 / 88
Factorization of form
P AP T = LDLT
with L unit lower triangular and D either tridiagonal or
block diagonal with 1 1 and 2 2 diagonal blocks, can be
computed stably using symmetric pivoting strategy
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Michael T. Heath
Symmetric Systems
Banded Systems
Iterative Methods
76 / 88
A = L LT
Scientific Computing
Cholesky Factorization
l11 =
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
79 / 88
Michael T. Heath
Scientific Computing
80 / 88
Symmetric Systems
Banded Systems
Iterative Methods
Band Matrices
Symmetric Systems
Banded Systems
Iterative Methods
Tridiagonal Matrices
Consider tridiagonal matrix
b1
a2
A=0
.
..
Scientific Computing
b2
..
.
c2
..
.
..
.
..
.
..
.
an1
0
bn1
an
0
..
.
cn1
bn
c1
81 / 88
Symmetric Systems
Banded Systems
Iterative Methods
Michael T. Heath
Scientific Computing
Symmetric Systems
Banded Systems
Iterative Methods
82 / 88
m2
L= 0
.
..
0
0
1
..
.
..
..
.
..
.
mn1
0
..
1
mn
0
..
.
.. ,
.
0
1
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
d1
U = ...
.
..
c1
d2
..
.
c2
..
.
..
..
.
..
.
dn1
0
0
..
.
cn1
dn
Scientific Computing
83 / 88
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Symmetric Systems
Banded Systems
Iterative Methods
85 / 88
Michael T. Heath
Existence, Uniqueness, and Conditioning
Solving Linear Systems
Special Types of Linear Systems
Software for Linear Systems
Level
1
Work
O(n)
O(n2 )
O(n3 )
Scientific Computing
86 / 88
Examples of BLAS
Michael T. Heath
Michael T. Heath
84 / 88
Scientific Computing
Examples
saxpy
sdot
snrm2
sgemv
strsv
sger
sgemm
strsm
ssyrk
Function
Scalar vector + vector
Inner product
Euclidean vector norm
Matrix-vector product
Triangular solution
Rank-one update
Matrix-matrix product
Multiple triang. solutions
Rank-k update
Michael T. Heath
Scientific Computing
88 / 88