Professional Documents
Culture Documents
Linear Systems
a11 x1 a12 x2 a13 x3 b1
a21 x1 a22 x2 a23 x3 b2
a31 x1 a32 x2 a33 x3 b3
a11
a21
a
31
a12
a13
a22
a23
a32
a33
x1 b1
x2 b2
x b
3 3
Linear Systems
Solve Ax=b, where A is an nn matrix and
b is an n1 column vector
Can also talk about non-square systems
where
A is mn, b is m1, and x is n1
Overdetermined if m>n:
more equations than unknowns
Underdetermined if n>m:
more unknowns than equations
Can look for best solution using least squares
Singular Systems
A is singular if some row is
linear combination of other rows
Singular systems can be
underdetermined:
2 x1 3 x2 5
4 x1 6 x2 10
or inconsistent:2 x1 3x2 5
4 x1 6 x2 11
Inverting a Matrix
Usually not a good idea to compute x=A -1b
Inefficient
Prone to roundoff error
Gauss-Jordan Elimination
Fundamental operations:
1. Replace one equation with linear combination
of other equations
2. Interchange two equations
Gauss-Jordan Elimination
Solve:
2 x1 3 x2 7
4 x1 5 x2 13
3
5
13
Gauss-Jordan Elimination
Given:
2
3
5
13
0
1
Gauss-Jordan Elimination
2
3
5
13
13
Gauss-Jordan Elimination
1
13
Negate row2
1
7
Gauss-Jordan Elimination
1
0
1
Gauss-Jordan Elimination
For each row i:
Multiply row i by 1/aii
For each other row j:
Add aji times row i to row j
Pivoting
Consider this system:
0
1
3
3
2
Pivoting
Conclusion: small diagonal elements
bad
Remedy: swap in larger element from
somewhere else
Partial Pivoting
0
1
3
3
1
Now continue:
1
0
1
Full Pivoting
0
1
3
Full Pivoting
3
1
1
2
0
2
3
2
0
1
Swap results
1 and 2
3
2
Operation Count
For one R.H.S., how many operations?
For each of n rows:
Do n times:
For each of n+1 columns:
One add, one multiply
Faster Algorithms
Our goal is an algorithm that does this
in
1/ n3 operations, and does not require
3
all R.H.S. to be known at beginning
Before we see that, lets look at a few
special cases that are even faster
Tridiagonal Systems
Common special case:
a11
a21
0
0
a12
a22
a23
a32
a33
a34
a43
a44
b1
b2
b3
b4
a21
0
0
a12
a22
a23
a32
a33
a34
a43
a44
b1
b2
b3
b4
Running Time
2n loops, 4 multiply/adds per loop
(assuming correct bookkeeping)
This running time has a fundamentally
different dependence on n: linear
instead of cubic
Can say that tridiagonal algorithm is O(n)
while
Gauss-Jordan is O(n3)
Big-O Notation
Informally, O(n3) means that the dominant
term for large n is cubic
More precisely, there exist a c and n0 such
that
running time c n3
if
n > n0
This type of asymptotic analysis is often
used
to characterize different algorithms
Triangular Systems
Another special case: A is lowertriangular
a11
a21
a31
a
41
a22
a32
a33
a42
a43
a44
b1
b2
b3
b4
Triangular Systems
Solve by forward substitution
a11
a21
a31
a
41
a22
a32
a33
a42
a43
a44
b1
x1
a11
b1
b2
b3
b4
Triangular Systems
Solve by forward substitution
a11
a21
a31
a
41
a22
a32
a33
a42
a43
a44
b2 a21 x1
x2
a22
b1
b2
b3
b4
Triangular Systems
Solve by forward substitution
a11
a21
a31
a
41
a22
a32
a33
a42
a43
a44
b3 a31 x1 a32 x2
x3
a33
b1
b2
b3
b4
Triangular Systems
If A is upper triangular, solve by
backsubstitution
a11
0
0
a12
a13
a14
a15
a22
a23
a24
a25
a33
a34
a35
a44
a45
a55
b5
x5
a55
b1
b2
b3
b4
b5
Triangular Systems
If A is upper triangular, solve by
backsubstitution
a11
0
0
a12
a13
a14
a15
a22
a23
a24
a25
a33
a34
a35
a44
a45
a55
x4
b4 a45 x5
a44
b1
b2
b3
b4
b5
Triangular Systems
Both of these special cases can be solved in
O(n2) time
This motivates a factorization approach to
solving arbitrary systems:
Find a way of writing A as LU, where L and U are
both triangular
Cholesky Decomposition
For symmetric matrices, choose U=LT
Perform decomposition
a11
a12
a
13
Ax=b
LTx=y
a12
a22
a23
a13
l11
a23 l21
l
a33
31
LLTx=b
0
l22
l32
0
l33
l11
0
0
l31
l32
l33
Ly=b
l21
l22
Cholesky Decomposition
a11
a12
a
13
a13
l11
a23 l21
l
a33
31
a12
a22
a23
0
l22
l32
0
l33
l11
0
0
l21
l22
0
a23 l21l31
l32
l22
l31
l32
l33
Cholesky Decomposition
a11
a12
a
13
a12
a22
a23
a13
l11
a23 l21
l
a33
31
0
l22
l32
0
l33
i 1
i 1
l ji
aij lik l jk
k 1
lii
l11
0
0
l21
l22
0
l31
l32
l33
Cholesky Decomposition
This fails if it requires taking square root
of a negative number
Need another condition on A: positive
definite
For any v, vT A v > 0
(Equivalently, all positive eigenvalues)
Cholesky Decomposition
Running time turns out to be 1/6n3
Still cubic, but much lower constant
LU Decomposition
Again, factor A into LU, where
L is lower triangular and U is upper
triangular
Ax=b
LUx=b
Ly=b
Ux=y
Crouts Method
a11
a21
a
31
a12
a22
a32
a13
l11
a23 l21
l
a33
31
0
l22
l32
0
l33
u11
0
0
u12
u22
0
u13
u23
u33
Crouts Method
a11
a21
a
31
a12
a22
a32
a13
1
a23 l21
l
a33
31
u11 a11
0
1
l32
0
1
u11
0
0
u12
u22
0
a21
u11
a
l31 31
u11
u12 a12
l21u12 u22 a22 u22 a22 l21u12
a l u
l31u12 l32u22 a32 l32 32 31 12
u22
u13
u23
u33
Crouts Method
a11
a21
a
31
a12
a22
a32
a13
1
a23 l21
l
a33
31
0
1
l32
0
1
For i = 1..n
For j = 1..i
j 1
u ji a ji l jk uki
k 1
For j = i+1..n
l ji
i 1
a ji l jk uki
k 1
uii
u11
0
0
u12
u22
0
u13
u23
u33
Crouts Method
Interesting note: # of outputs = # of inputs,
algorithm only refers to elements not output
yet
Can do this in-place!
Algorithm replaces A with matrix
of l and u values, 1s are implied
u11
l21
l
31
u12
u22
l32
u13
u 23
u33
LU Decomposition
Running time is 1/3n3
Only a factor of 2 slower than symmetric
case