Professional Documents
Culture Documents
Chapter 3 Systems of Equations
Chapter 3 Systems of Equations
System of Equations
3.1 Direct methods for system of linear equations (SLE)
3.1.1 Gaussian method
3.1.2 Gaussian method with partial pivoting
3.1.3 Jordan's method
3.1.4 Jordan’s method for matrix inversion
3.1.5 Matrix decomposition
2
Gaussian Elimination Method
A method to solve simultaneous linear
equations of the form AX=C
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
Cont…
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 an3 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
Cont...
Subtract the result from Equation 2.
a21 x1 a22 x2 a23 x3 ... a2 n 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
Cont...
Repeat this procedure for the remaining
equations to reduce the set of equations as
a11 x1 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
Cont...
Step 2
Repeat the same procedure for the 3rd term of
Equation 3.
a11 x1 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 (n 1 )
0 ann xn bn(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
Cont…
Start with the last equation because it has only one unknown
( n 1)
b
xn n
( n 1)
a nn
Cont…
( n 1)
b
xn n
( n 1)
a nn
25 5 1 a1 106.8
64
8 1 a 2 177.2
144 12 1 a3 279.2
Cont…
25 5 1 a1 106.8 25 5 1 106.8
64 8 1 a 2 177.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
Number of steps of forward elimination is
(n1)(31)2
Forward Elimination: Step 1
25 5 1 106.8 Divide Equation 1 by 25 and
64 8 1 177.2
64
144 12 1 279.2 multiply it by 64, 2.56 .
25
. 64 8 1 177.2
Subtract the result from 64 12.8 2.56 273.408
Equation 2
0 4.8 1.56 96.208
25 5 1 106.8
Substitute new equation for 0 4.8 1.56 96.208
Equation 2
144 12 1 279.2
Cont...
25 5 1 106.8 Divide Equation 1 by 25 and
0 4.8 1.56 96.208
144 12 1 279.2 multiply it by 144, 144 5.76 .
25
144 279.2
.
12 1
Subtract the result from 144 28.8 5.76 615.168
Equation 3
0 16.8 4.76 335.968
25 5 1 106.8
Substitute new equation for 0 4.8 1.56 96.208
Equation 3
0 16.8 4.76 335.968
Forward Elimination: Step 2
25 5 1 106.8 Divide Equation 2 by −4.8
0 4.8 1.56 96.208
and multiply it by −16.8,
0 16.8 4.76 335.968 16.8
. 3.5
4.8
0 4.8 1.56 96.208 3.5 0 16.8 5.46 336.728
0 16.8 4.76 335.968
Subtract the result from
Equation 3 0 16.8 5.46 336.728
0 0 0.7 0.76
25 5 1 106.8
Substitute new equation for 0 4.8 1.56 96.208
Equation 3
0 0 0.7 0.76
Back Substitution
25 5 1 106.8 25 5 1 a1 106.8
0 4.8 1.56 96.2 0 4.8 1.56 a 96.208
2
0 0 0.7 0.7 0 0 0.7 a3 0.76
Solving for a3
0.7 a3 0.76
0.76
a3
0.7
a3 1.08571
Cont...
25 5 1 a1 106.8
0 4.8 1.56 a 96.208
2
0 0 0.7 a3 0.76
Solving for a2
4.8a2 1.56a3 96.208
96.208 1.56a3
a2
4.8
96.208 1.56 1.08571
a2
4.8
a2 19.6905
Cont...
25 5 1 a1 106.8
0 4.8 1.56 a 96.2
2
0 0 0.7 a3 0.76
Solving for a1
25a1 5a2 a3 106.8
106.8 5a2 a3
a1
25
106.8 5 19.6905 1.08571
25
0.290472
Gaussian Elimination Solution
25 5 1 a1 106.8
64 8 1 a2 177.2
144 12 1 a3 279.2
a1 0.290472
a 19.6905
2
a3 1.08571
Cont…
Solution a1 0.290472
a 19.6905
The solution vector is
2
a3 1.08571
The polynomial that passes through the three data points is then:
difficulty#1. Division by zero
10 x2 7 x3 3
6 x1 2 x2 3x3 11
5x1 x2 5x3 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 5x2 3x3 14
5x1 x2 5x3 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 5x2 3x3 14
24 x1 x2 5x3 28
20 15 10 x1 45
3 2.249 7 x 1.751
2
5 x 1 1
1
3 x3 9
x 1
2
x3 1
Exact Solution
Cont...
20 15 10 x1 45
3 2.249 7 x 1.751
2
5 1 3 x3 9
36
Row pivoting
0 a'n 2 an' 3 an' 4 ann'
xn bn'
Cont...
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 x4 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 x4 9
0 7 6 1 2 x5 6
Switched Rows
Gaussian Elimination
with Partial Pivoting
Two steps
1. Forward Elimination
2. Back Substitution
Matrix Form at the Beginning of 2nd Step
of Forward Elimination
0 a'n 2 ' '
an 3 an 4 '
ann xn bn
'
Matrix Form at the End of Forward
Elimination
0 0 0 (n 1 )
0 ann xn bn
(n-1 )
Back Substitution Starting Eqns
a11 x1 a12 x2 a13 x3 ... a1n xn 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 xj
j i 1
xi i 1 for i n 1,...,1
a ii
Example 2
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 a3 279.2
Cont…
25 5 1 a1 106.8 25 5 1 106.8
64 8 1 a 177.2 64 8 1 177.2
2
144 12 1 a3 279.2 144 12 1 279.2
1. Forward Elimination
2. Back Substitution
Forward Elimination: Step 1
• Examine absolute values of first column, first row
and below.
25 , 64 , 144
144 12 1 279.2
Substitute new equation for 0 2.667 0.5556 53.10
Equation 2
25 5 1 106.8
Cont...
144 12 1 279.2 Divide Equation 1 by 144 and
0 2.667 0.5556 53.10 25
multiply it by 25, 0.1736.
25 5 1 106.8 144
25 1 106.8
.
5
Subtract the result from 25 2.083 0.1736 48.47
Equation 3
0 2.917 0.8264 58.33
144 12 1 279.2
Substitute new equation for 0 2.667 0.5556 53.10
Equation 3
0 2.917 0.8264 58.33
Step 2
• Examine absolute values of second column, second row
and below.
2.667 , 2.917
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
Solving for a3
0.2a3 0.23
0.23
a3
0.2
1.15
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.917 a2 0.8264 a3 58.33
58.33 0.8264 a3
a2
2.917
58.33 0.8264 1.15
2.917
19.67
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
Gaussian Elimination Solution
25 5 1 a1 106.8
64 8 1 a2 177.2
144 12 1 a3 279.2
a1 0.290472
a 19.6905
2
a3 1.08571
Partial Pivoting: Example 3
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 x 3 6
10 7 0 x1 7
10 7 0 x1 7
3 2.099 6 x 3.901 0 0.001 6 x 6.001
2 2
5 1 5 x3 6 0 2.5 5 x3 2.5
Cont...
Forward Elimination: Step 2
Examining the values of the first column
|-0.001| and |2.5| or 0.0001 and 2.5
The largest absolute value is 2.5, so row 2 is switched with
row 3
10 7 0 x1 7 10 7 0 x1 7
0 0.001 6 x 6.001 0 2.5 5 x 2.5
2 2
0 2.5 5 x3 2.5 0 0.001 6 x3 6.001
Cont...
Forward Elimination: Step 2
10 7 0 x1 7
0 2.5 5 x 2.5
2
0 0 6.002 x3 6.002
Cont...
Back Substitution
Solving the equations through back substitution
10 7 0 x1 7
x3
6.002
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 x2 0 x3
x1 0
10
Cont...
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
Gauss-Jordan Method
• The Gauss-Jordan Method is similar to the
Gaussian Elimination.
2 3 7
4 5 13
Gauss-Jordan Elimination
• Given:
2 3 7
4 5 13
• Goal: reduce this to trivial system
1 0 ?
0 1 ?
and read off answer from right column
Gauss-Jordan Elimination
2 3 7
4 5 13
1 3
2
7 2
4 5 13
1 3
2
7 2
0 1 1
x y 2z 0 1 1 2 0 2 R1 R3 R3
2 2 4 0
x 2 y 3 z 1 0 1 1 1 2 2 1 3
2 x 2 y z 3 0 0 3 3 0 0 3 3
Cont…
• Solve the system of equations using Gauss-
Jordan Method
x y 2z 0 1 1 2 0 1R2 R2
0 1 1 1
x 2 y 3 z 1 0 1 1 1
2 x 2 y z 3 0 0 3 3
Cont…
• Solve the system of equations using Gauss-
Jordan Method
x y 2z 0 1 1 2 0 1R2 R2
0 1 1 1
x 2 y 3 z 1 0 1 1 1
2 x 2 y z 3 0 0 3 3
Cont…
• Solve the system of equations using Gauss-
Jordan Method
R2 R1
x y 2z 0 1 1 2 0 R1
0 1 1 1
x 2 y 3 z 1 0 1 1 1 1 1 2 0
2 x 2 y z 3 0 0 3 3 1 0 1 1
Cont…
• Solve the system of equations using Gauss-
Jordan Method
R2 R1
x y 2z 0 1 0 1 1 R1
0 1 1 1
x 2 y 3 z 1 0 1 1 1 1 1 2 0
2 x 2 y z 3 0 0 3 3 1 0 1 1
Cont…
• Solve the system of equations using Gauss-
Jordan Method
1
x y 2z 0 1 0 1 1 R3 R3
3
x 2 y 3 z 1 0 1 1 1
0 0 1 1
2 x 2 y z 3 0 0 3 3
Cont…
• Solve the system of equations using Gauss-
Jordan Method
1
x y 2z 0 1 0 1 1 R3 R3
3
x 2 y 3 z 1 0 1 11
0 0 1 1
2 x 2 y z 3 0 0 1 1
Cont…
• Solve the system of equations using Gauss-
Jordan Method
R3 R2
x y 2z 0 1 0 1 1 R2
0 0 1 1
x 2 y 3 z 1 0 1 11 0 1 1 1
2 x 2 y z 3 0 0 1 1 0 1 0 2
Cont…
• Solve the system of equations using Gauss-
Jordan Method
R3 R2
x y 2z 0 1 0 1 1 R2
0 0 1 1
x 2 y 3 z 1 0 1 0 2 0 1 1 1
2 x 2 y z 3 0 0 1 1 0 1 0 2
Cont…
• Solve the system of equations using Gauss-
Jordan Method
R3 R1 R1
x y 2z 0 1 0 1 1
0 0 1 1
x 2 y 3 z 1 0 1 0 2 1 0 1 1
2 x 2 y z 3 0 0 1 1 1 0 0 0
Cont…
• Solve the system of equations using Gauss-
Jordan Method
R3 R1 R1
x y 2z 0 1 0 0 0
0 0 1 1
x 2 y 3 z 1 0 1 0 2 1 0 1 1
2 x 2 y z 3 0 0 1 1 1 0 0 0
Cont…
• Solve the system of equations using Gauss-
Jordan Method
x y 2z 0 1 0 0 0
(0, 2, 1)
x 2 y 3 z 1 0 1 0 2
2 x 2 y z 3 0 0 1 1
LU Decomposition Method
LU Decomposition is another method to solve a set of
simultaneous linear equations.
For most non-singular matrix [A] that one could conduct
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 [A][X] = [C]
equations [L][U][X] = [C]
If [A] = [L][U] then [L]-1
Multiply by [L]-1[L][U][X] = [L]-1[C]
Which gives [I][U][X] = [L]-1[C]
Remember [L]-1[L] = [I] which [U][X] = [L]-1[C]
leads to
[L]-1[C]=[Z]
Now, if [I][U] = [U] then
[L][Z] = [C] (1)
Now, let
[U][X] = [Z] (2)
Which ends with
and
LU Decomposition
How can this be used?
94
Decompose [A] to [L] and [U]
25 5 1
64 8 1
144 12 1
25 5 1
2.56; Row2 Row12.56 0 4.8 1.56
64
Step 1:
25
144 12 1
25 5 1
5.76; Row3 Row15.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 Row23.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
a 21 64
25 5 1 21 2.56
From the first 64 8 1 a11 25
step of forward a31 144
elimination 144 12 1 31 5.76
a11 25
Finding the [L] Matrix
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
?
3.2 Indirect Methods for Solving SLE
Gauss Jacobi method
Gauss Seidel method
Iterative Techniques
• The method of solving simultaneous linear algebraic
equations using Gaussian Elimination and the Gauss-
Jordan Method. These techniques are known as
direct methods.
• Problems can arise from round-off errors and zero on
the diagonal.
• One means of obtaining an approximate solution to
the equations is to use an “educated guess”.
Iterative Methods
• Start with x y 1/ 2
(1) (1)
• Con’t
1 ( 2) 11 13
x (3)
y 3 3
2 8 8
1 ( 2) 11 13
y (3)
x 3 3
2 8 8
Jacobi Method
• Consider the three-by-three system
2 x1 x2 x3 1
x1 2 x2 x3 6
x1 x2 2 x3 3
x1 0.5x2 0.5x3 0.5
x2 0.5 x1 0.5x3 3.0
x3 0.5 x1 0.5 x2 1.5
xij xij 1
a ,i j < s
100%
xi
b1 a12
u ( x1 , x2 ) x2
a11 a11
b2 a21
v( x1 , x2 ) x1
a22 a22
u u a12
0
x1 x2 a11
v a21 v
0
x1 a22 x2
• Substitution into convergence criterion of two linear
equations yield:
a12 a21
<1
<1
a11 a22
• In other words, the absolute values of the
slopes must be less than unity for convergence:
a11 > a12
a22
> a21
For n equations :
n
aii > ai , j
j 1
j i
Gauss-Seidel Method
Basic Procedure:
-Algebraically solve each linear equation for xi
-Assume an initial guess solution array
-Solve for each xi and repeat
-Use absolute relative approximate error after each iteration to
check if error is within a pre-specified tolerance.
Gauss-Seidel Method
Why?
If the physics of the problem are understood, a close initial guess can
be made, decreasing the number of iterations needed.
Gauss-Seidel Method
Algorithm
A set of n equations and n unknowns:
a11 x1 a12 x2 a13 x3 ... a1n xn b1
a21 x1 a22 x2 a23 x3 ... a2n xn b2
. .
. .
. .
c2 a21 x1 a23 x3 a2 n xn
x2 From equation 2
a22
cn 1 an 1,1 x1 an 1, 2 x2 an 1,n 2 xn 2 an 1,n xn From equation n-1
xn 1
an 1,n 1
cn an1 x1 an 2 x2 an ,n 1 xn 1 From equation n
xn
ann
Gauss-Seidel Method
Algorithm
General Form of each equation
n
a
n
c1 a1 j x j cn 1 n 1, j xj
j 1 j 1
j n 1
x1
j 1 xn 1
a11 an 1,n 1
n
cn a nj x j
n
c2 a2 j x j
j 1 j 1
j n
x2
j 2
xn
a 22 a nn
Gauss-Seidel Method
Algorithm
General Form for any row ‘i’
n
ci aij x j
j 1
j i
xi , i 1,2,, n.
aii
Gauss-Seidel Method
Solve for the unknowns
Assume an initial guess for [X]
Use rewritten equations to solve for
x1 each value of xi.
xn-1
xn
Gauss-Seidel Method
Calculate the Absolute Relative Approximate Error
x inew x iold
a i new
100
xi
So when has the answer been found?
The inequalities are all true and at least one row is strictly greater than:
Therefore: The solution should converge using the Gauss-Siedel Method
Gauss-Seidel Method: Example
12 3 5 a1 1 x1 1
1 5 3 a 28 With an initial guess of x 0
2 2
3 7 13 a3 76 x3 1
4.9000 0
a 2
100 100.00%
4.9000
3.0923 1.0000
a 3
100 67.662%
3.0923
The maximum absolute relative error after the first iteration is 100%
Gauss-Seidel Method: Example
After Iteration #1
x1 0.5000
x 4.9000
2
x3 3.0923
After Iteration #2
Substituting the x values into the equations
1 34.9000 53.0923 x1 0.14679
x1 0.14679 x 3.7153
12 2
x3 3.8118
28 0.14679 33.0923
x2 3.7153
5
76 30.14679 74.900
x3 3.8118
13
Gauss-Seidel Method: Example
Iteration #2 absolute relative approximate error
0.14679 0.50000
a 1 100 240.62%
0.14679
3.7153 4.9000
a 2
100 31.887%
3.7153
3.8118 3.0923
a 3 100 18.876%
3.8118
The maximum absolute relative error after the second iteration is 240.62%
Gauss-Seidel Method: Example
Repeating more iterations, the following values are obtained
Iteration a1
a 1 a2
a 2
a3
a 3
x1 0.99919
The solution obtained
x
2 3.0001
x3 4.0001
x1 1
is close to the exact solution of x2 3
x3 4
3.3 Newton’s Method for
System of non-linear Equations
• Consider a non linear system of equations
f1 ( x1 , x2 ,..., xn ) 0
f 2 ( x1 , x2 ,..., xn ) 0
f n ( x1 , x2 ,..., xn ) 0
Cont...
• The totality of the arguments x1 , x2 ,...,xn
May be considered as an n-dimenstional vector.
x1 f1
x2 f2
x f
x f
n n
Therefore, the above system f ( x) 0
Cont...
• System f ( x) 0 is solved by the method of Successive
approximations.
• Suppose the kth approximation
x ( x , x ,..., x )
k k
1
k
2
k T
n
f ( x k e k ) f ( x k ) f ' ( x k )e k 0
Cont...
Where f1 f1 f
1
x x2 xn
1
f ( x )
' k
W (xk )
f n f n f n
x1 x2 xn
f ( x k ) w( x k )e k 0
Then w( x 0 )(e 0 ) f ( x 0 )
1 1 1 e1 0.25
0
2 1 4 e 0 1.25
2
3 4 1 e3 1.00
0
Cont...
• Then using Gaussian Elimination Method we solve
x1 x 0 e 0
x11 0.875
1
2
x 0.500
x1 0.375
3