Professional Documents
Culture Documents
6-Sys Linear Eqns-I
6-Sys Linear Eqns-I
b0 = b1 = b2 = ... = 2
Numerical Analysis
Two steps
1. Forward Elimination
2. Back Substitution
Forward Elimination
The goal of forward elimination is to transform the
coefficient matrix into an upper triangular matrix
25 5 1 x1 106.8
64 8 1 x = 177.2
2
144 12 1 x3 279.2
25 5 1 x1 106.8
0 − 4.8 − 1.56 x = − 96.21
2
0 0 0.7 x3 0.735
Forward Elimination
A set of n equations and n unknowns
a11 x1 + a12 x2 + a13 x3 + ... + a1n xn = b1
a21 x1 + a22 x2 + a23 x3 + ... + a2 n xn = b2
. .
. .
. .
an1 x1 + an 2 x2 + an 3 x3 + ... + ann xn = bn
a21
a ( a11 x1 + a12 x2 + a13 x3 + ... + a1n xn = b1 )
11
a21 a21 a21
a21 x1 + a12 x2 + ... + a1n xn = b1
a11 a11 a11
Forward Elimination
Subtract the result from Equation 2.
a21x1 + a22 x2 + a23 x3 + ... + a2n xn = b2
a21 a21 a21
− a21 x1 + a a12 x2 + ... + a a1n xn = a b1
_________________________________________________
11 11 11
or a x + ... + a x = b
'
22 2
'
2n n
'
2
Forward Elimination
Repeat this procedure for the remaining
equations to reduce the set of equations as
a11x1 + a12 x2 + a13 x3 + ... + a1n xn = b1
'
a22 x2 + a23
'
x3 + ... + a2' n xn = b2'
'
a32 x2 + a33
'
x3 + ... + a3' n xn = b3'
. . .
. . .
. . .
End of Step 1
Forward Elimination
Step 2
Repeat the same procedure for the second
column.
a11x1 + a12 x2 + a13 x3 + ... + a1n xn = b1
'
a22 x2 + a23
'
x3 + ... + a2' n xn = b2'
"
a33 x3 + ... + a3" n xn = b3"
. .
. .
. .
( n −1) (n −1 )
ann xn = bn
0 0 0 0 ann xn bn
(n −1 )
(n-1 )
Back Substitution
Solve each equation starting from the last equation
25 5 1 x1 106.8
0 − 4.8 − 1.56 x = − 96.21
2
0 0 0.7 x3 0.735
( n −1) (n −1 )
ann xn = bn
Back Substitution
Start with the last equation because it has only one unknown
( n −1)
b
xn = n
( n −1)
a nn
Back Substitution
( n −1)
b
xn = n
( n −1)
a nn
(i −1)
− aij(i −1) x j
n
bi
j =i +1
xi = (i −1) for i = n − 1,...,1
a ii
Naive Gauss Elimination
Pitfalls
Pitfall#1. Division by zero
10 x2 − 7 x3 = 3
6 x1 + 2 x2 + 3x3 = 11
5 x1 − x2 + 5 x3 = 9
0 10 − 7 x1 3
6 2 3 x2 = 11
5 − 1 5 x3 9
Is division by zero an issue here?
12 x1 + 10 x2 − 7 x3 = 15
6 x1 + 5 x2 + 3x3 = 14
5 x1 − x2 + 5 x3 = 9
12 10 − 7 x1 15
6 5 3 x2 = 14
5 − 1 5 x3 9
Is division by zero an issue here?
YES
12 x1 + 10 x2 − 7 x3 = 15
6 x1 + 5 x2 + 3x3 = 14
24 x1 − x2 + 5 x3 = 28
Exact Solution
x1 1
x = 1
2
x3 1
Pitfall#2. Large Round-off Errors
20 15 10 x1 45
− 3 − 2.249 7 x = 1.751
2
5 1 3 x3 9
0 a'n 2 ' '
an 3 an 4 ann xn bn
'
'
Example (2nd step of FE)
6 14 5.1 3.7 6 x1 5
0 − 7 6 1 2 x 2 − 6
0 4 12 1 11 x3 = 8
0 9 23 6 8 x 4 9
0 − 17 12 11 43 x5 3
6 14 5.1 3.7 6 x1 5
0 − 17 12 11 43 x 3
2
0 4 12 1 11 x3 = 8
0 9 23 6 8 x
4 9
0 − 7 6 1 2 x5 − 6
Switched Rows
Gaussian Elimination
with Partial Pivoting
A method to solve simultaneous linear
equations of the form [A][X]=[C]
Two steps
1. Forward Elimination
2. Back Substitution
Forward Elimination
Same as naive Gauss elimination method
except that we switch rows before each
of the (n-1) steps of forward elimination.
Matrix Form at the End of Forward
Elimination
a11 a12 a13 a1n x1 b1
0 a' '
a23 '
a 2 n x2 b2'
22
0 0 "
a33 a3n x3 = b3
" "
0 0 0 0 ann xn bn
(n −1 )
(n-1 )
Back Substitution Starting Eqns
a11 x1 + a12 x 2 + a13 x3 + ... + a1n x n = b1
'
a22 x2 + a23
'
x3 + ... + a2' n xn = b2'
"
a33 x3 + ... + an" xn = b3"
. .
. .
. .
( n −1) (n −1 )
ann xn = bn
Back Substitution
( n −1)
b
xn = n
( n −1)
a nn
(i −1) n
(i −1)
bi − aij x j
j =i +1
xi = (i −1) for i = n − 1,...,1
a ii
Example
Solve the following set of equations
by Gaussian elimination with partial
pivoting
25 5 1 a1 106.8
64
8 1 a 2 = 177.2
144 12 1 a 3 279.2
Example Cont.
25 5 1 a1 106.8 25 5 1 106.8
64 8 1 a = 177.2
2 64 8 1 177.2
144 12 1 a3 279.2 144 12 1 279.2
1. Forward Elimination
2. Back Substitution
Forward Elimination
Number of Steps of Forward
Elimination
.
0 2.667 0.5556 53.10
Subtract the result from − 0 2.667 0.7556 53.33
Equation 3
0 0 − 0.2 − 0.23
144 12 1 279.2
Substitute new equation for 0 2.917 0.8264 58.33
Equation 3
0 0 − 0.2 − 0.23
Back Substitution
Back Substitution
144 12 1 279.2 144 12 1 a1 279.2
0 2.917 0.8264 58.33 0 2.917 0.8264 a = 58.33
2
0 0 − 0.2 − 0.23 0 0 − 0.2 a3 − 0.23
Solving for a3
− 0.2a3 = −0.23
− 0.23
a3 =
− 0.2
= 1.15
Back Substitution (cont.)
144 12 1 a1 279.2
0 2.917 0.8264 a = 58.33
2
0 0 − 0.2 a3 − 0.23
Solving for a2
2.917a2 + 0.8264a3 = 58.33
58.33 − 0.8264a3
a2 =
2.917
58.33 − 0.8264 1.15
=
2.917
= 19.67
Back Substitution (cont.)
144 12 1 a1 279.2
0 2.917 0.8264 a = 58.33
2
0 0 − 0.2 a3 − 0.23
Solving for a1
144a1 + 12a2 + a3 = 279.2
279.2 − 12a2 − a3
a1 =
144
279.2 − 12 19.67 − 1.15
=
144
= 0.2917
Gaussian Elimination with Partial
Pivoting Solution
25 5 1 a1 106.8
64 8 1 a = 177.2
2
144 12 1 a3 279.2
a1 0.2917
a = 19.67
2
a3 1.15
Partial Pivoting: Example
Consider the system of equations
10 x1 − 7 x2 = 7
− 3x1 + 2.099 x2 + 6 x3 = 3.901
5 x1 − x2 + 5 x3 = 6
In matrix form
10 − 7 0 x1 7
− 3 2.099 6 x 3.901
2 =
5 − 1 5 x3 6
10 − 7 0 x1 7
0 2.5 5 x = 2.5
2
0 0 6.002 x3 6.002
Partial Pivoting: Example
Back Substitution
Solving the equations through back substitution
10 − 7
6.002
0 x1 7 x3 = =1
0 2.5 5 x = 2.5 6.002
2
0 0 6.002 x3 6.002 2.5 − 5 x3
x2 = = −1
2.5
7 + 7 x 2 − 0 x3
x1 = =0
10
Partial Pivoting: Example
Compare the calculated and exact solution
The fact that they are equal is coincidence, but it
does illustrate the advantage of Partial Pivoting
x1 0 x1 0
X calculated = x2 = − 1 X exact = x 2 = − 1
x3 1 x3 1
LU Decomposition
LU Decomposition is another method to solve a set of
simultaneous linear equations
LU Decomposition
Method
For most non-singular matrix [A] that one could conduct Naive Gauss
Elimination forward elimination steps, one can always write it as
[A] = [L][U]
where
[L] = lower triangular matrix
[U] = upper triangular matrix
How does LU Decomposition work?
If solving a set of linear equations [A][X] = [C]
If [A] = [L][U] then [L][U][X] = [C]
Multiply by [L]-1
Which gives [L]-1[L][U][X] = [L]-1[C]
Remember [L]-1[L] = [I] which leads to [I][U][X] = [L]-1[C]
Now, if [I][U] = [U] then [U][X] = [L]-1[C]
Now, let [L]-1[C]=[Z]
Which ends with [L][Z] = [C] (1)
and [U][X] = [Z] (2)
LU Decomposition
How can this be used?
8n 3 4n 8n 3 4n
T + 12n 2 + T + 12n 2 +
3 3 3 3
[U] is the same as the coefficient matrix at the end of the forward elimination step.
[L] is obtained using the multipliers that were used in the forward elimination process
Finding the [U] matrix
Using the Forward Elimination Procedure of Gauss Elimination
25 5 1
64 8 1
144 12 1
25 5 1
= 2.56; Row2 − Row1(2.56) = 0 − 4.8 − 1.56
64
Step 1:
25
144 12 1
25 5 1
= 5.76; Row3 − Row1(5.76) = 0 − 4.8 − 1.56
144
25
0 − 16.8 − 4.76
Finding the [U] Matrix
25 5 1
Matrix after Step 1: 0 − 4.8 − 1.56
0 − 16.8 − 4.76
25 5 1
− 16.8
Step 2: = 3.5; Row3 − Row2(3.5) = 0 − 4.8 − 1.56
− 4.8
0 0 0.7
25 5 1
U = 0 − 4.8 − 1.56
0 0 0.7
Finding the [L] matrix
1 0 0
1 0
21
31 32 1
1 0 0
L = 2.56 1 0
5.76 3.5 1
Does [L][U] = [A]?
1 0 0 25 5 1
LU = 2.56 1 0 0 − 4.8 − 1.56 =
5.76 3.5 1 0 0 0.7
?
Using LU Decomposition to solve SLEs
Solve the following set of 25 5 1 x1 106.8
linear equations using LU 64 8 1 x = 177.2
Decomposition 2
144 12 1 x3 279.2
Using the procedure for finding the [L] and [U] matrices
1 0 0 25 5 1
A = LU = 2.56 1 0 0 − 4.8 − 1.56
5.76 3.5 1 0 0 0.7
Example
z1 = 106.8
z 2 = 177.2 − 2.56 z1 z1 106.8
= 177.2 − 2.56(106.8)
= −96.2
Z = z2 = − 96.21
z3 = 279.2 − 5.76 z1 − 3.5 z 2 z3 0.735
= 279.2 − 5.76(106.8) − 3.5(− 96.21)
= 0.735
Example
Set [U][X] = [Z]
25 5 1 x1 106.8
0 − 4.8 − 1.56 x = − 96.21
2
0 0 0.7 x3 0.735
x3 =
0.735 − 96.21 + 1.56 x3
x2 =
0.7 − 4.8
x3 = 1.050 − 96.21 + 1.56(1.050)
x2 =
− 4.8
x2 = 19.70
Example
Substituting in x3 and x2 using Hence the Solution Vector is:
the first equation
25 x1 + 5 x2 + x3 = 106.8 x1 0.2900
106.8 − 5 x2 − x3 x = 19.70
x1 =
25
2
106.8 − 5(19.70) − 1.050
x3 1.050
=
25
= 0.2900
Finding the inverse of a square matrix
Using the decomposition procedure, the [L] and [U] matrices are found to be
1 0 0 25 5 1
A = LU = 2.56 1 0 0 − 4.8 − 1.56
5.76 3.5 1 0 0 0.7
Example: Inverse of a Matrix
Solving for the each column of [B] requires two steps
1) Solve [L] [Z] = [C] for [Z]
2) Solve [U] [X] = [Z] for [X]
1 0 0 z1 1
Step 1: LZ = C → 2.56 1 0 z2 = 0
5.76 3.5 1 z3 0
This generates the equations:
z1 = 1
2.56 z1 + z 2 = 0
5.76 z1 + 3.5 z 2 + z3 = 0
Example: Inverse of a Matrix
Solving for [Z]
z1 = 1
z1 1
z 2 = 0 − 2.56 z1
= 0 − 2.56(1)
Z = z2 = − 2.56
= −2.56 z3 3.2
z3 = 0 − 5.76 z1 − 3.5 z 2
= 0 − 5.76(1) − 3.5(− 2.56)
= 3.2
Example: Inverse of a Matrix
25 5 1 b11 1
Solving [U][X] = [Z] for [X] 0 − 4.8 − 1.56 b = − 2.56
21
0 0 0.7 b31 3.2