Lecture01 - Gaussian Elimination
Transcript of Lecture01 - Gaussian Elimination
-
8/9/2019 Lecture01 - Gaussian Elimination
1/27
Solution of Linear System of Equations
Lecture 1:
Gaussian Elimination
MTH2212 Computational Methods and Statistics
-
8/9/2019 Lecture01 - Gaussian Elimination
2/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 22
Objectives
Introduction
Gaussian Elimination
Pitfalls in Gauss Elimination Method
Pivoting
Scaling
-
8/9/2019 Lecture01 - Gaussian Elimination
3/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 33
Introduction
Well see how to solve a set ofn linearequations with nunknowns.
If n 3, the small set of linearequations can be solved
analytically. Simultaneous linearequations arise in a variety of
engineering problems context i.e. trusses, reactors, electric
circuits,
Broadly there are two types of methods to solve the linear
equations: Direct methods and Iterative methods.
-
8/9/2019 Lecture01 - Gaussian Elimination
4/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 44
Gaussian Elimination
Solving a set ofn linearequations:
Solution consists of two phases:1. Forward elimination of unknowns
2. Back substitution
!
!
!
nnnnnnn
nn
nn
bxaxaxaxa
bxaxaxaxa
bxaxaxaxa
...
.
.
.
...
...
332211
22323222121
11313212111(1a)
(1b)
(1c)
-
8/9/2019 Lecture01 - Gaussian Elimination
5/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 55
Gaussian Elimination
1. Forward elimination of the unknowns Eliminate the first unknown, x1, from the second through the n
th equations.Multiply equation (1) by a21/a11
Subtract equation (2) from equation (1b) to get
or
where the prime indicates the new values for the elements.
1
11
211
11
21313
11
21212
11
21121 ... ba
a
xaa
a
xaa
a
xaa
a
xa nn !
1
11
2121
11
212313
11
2123212
11
2122 )(...)()( b
a
abxa
a
aaxa
a
aaxa
a
aa
nnn!
(2)
(3)
'
2
'
23
'
232
'
22... bxaxaxa
nn!
-
8/9/2019 Lecture01 - Gaussian Elimination
6/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 66
Gaussian Elimination
Similarly equation (1) can be multiplied by a 1/a11 and the result subtracted
from the third equation.
Repeating the procedure for the remaining equations give the following
modified forms:
''
3
'
32
'
2
'
2
'
23
'
232
'
22
11313212111
...
.
.
.
...
...
nnnnnn
nn
nn
bxaxaxa
bxaxaxa
bxaxaxaxa(4a)
(4b)
(4c)
-
8/9/2019 Lecture01 - Gaussian Elimination
7/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 77
Gaussian Elimination
The second unknown x2 is eliminated by multiplying through the next
equation by a 2/a22 and subtracting the result from the following
equation.
The procedure is continued using the remaining pivot equations. At the
end of the elimination stage, the original system of equations istransformed to an upper triangular system:
!
!
!
)1()1(
'
2
'
23
'
232
'
22
11313212111
.
.
.
...
...
n
nn
n
nn
nn
nn
bxa
bxaxaxa
bxaxaxaxa
(5a)
(5b)
(5c)
-
8/9/2019 Lecture01 - Gaussian Elimination
8/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 88
Gaussian Elimination
2. Back Substitution
The last unknown xn is now given by:
This value of xn is then back-substituted into equation (n-1) to find xn-1.
This procedure can be repeated to evaluate the values of the remaining xs.
)1(
)1(
!n
nn
n
nn
a
bx (6)
-
8/9/2019 Lecture01 - Gaussian Elimination
9/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 99
-
8/9/2019 Lecture01 - Gaussian Elimination
10/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 1010
Example 1
Use Gauss elimination to solve:
3x1 0.1x2 0.2x3 = 7.85 (a)
0.1x1 + 7x2 0.3x3 = -19.3 (b)
0.3x1 0.2x2 + 10x3 = 71.4 (c)
use 6 significant figures in your computation.
-
8/9/2019 Lecture01 - Gaussian Elimination
11/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 1111
Solution of Example 1
1. Forward elimination Multiply 1st equation (a) by 0.1/ and subtract from 2nd equation (b) to eliminate
x1 from the latter equation:
7.00 x2 0.29 x = -19.5617
Then multiply 1st equation (a) by 0. / and subtract from rd equation (c) toeliminate x1 from the latter equation:
-0.190000x2 + 10.0200x = 70.6150
The system of equations is now:
x1 0.1x2 0.2x = 7.85 (a)
7.00 x2 0.29 x = -19.5617 (b)
-0.190000x2 + 10.0200x = 70.6150 (c)
-
8/9/2019 Lecture01 - Gaussian Elimination
12/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 1212
Solution of Example 1
Now lets eliminate x2 from latestrd equation (c) by multiplying equation (b)
by -0.190000/7.00 and subtract the result from equation (c):
10.0200x = 70.084
The system of equations is now reduced to an upper triangular form:
x1 0.1 x2 0.2 x = 7.85 (a)
7.00 x2 0.29 x = -19.5617 (b)
10.0200 x = 70.084 (c)
-
8/9/2019 Lecture01 - Gaussian Elimination
13/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 1313
Solution of Example 1
2. Back Substitution
Solve last equation (c) to find x :
x = 70.084 /10.0200 = 7.0000
Substitute x in equation (b) and solve for x2 :
7.00 x2 0.29 (7.0000 ) = -19.5617
x2 = -2.50000
Finally substitute values of x2 and x in equation (a) to find x1 :
x1 0.1(-2.5000) 0.2(7.0000 ) = 7.85
x1 = .00000
-
8/9/2019 Lecture01 - Gaussian Elimination
14/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 1414
Solution of Example 1
3. Check yourresults
Substitute the values of x1 , x2 and x in the original system of equations.
( .00000) 0.1 (-2.50000) 0.2 (7.0000 ) = 7.84999
0.1 ( .00000) + 7 (-2.50000) 0. (7.0000 ) = -19. 0000
0. ( .00000) 0.2 (-2.50000) + 10 (7.0000 ) = 71.400 0
-
8/9/2019 Lecture01 - Gaussian Elimination
15/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 1515
Some Pitfalls of Gauss Elimination Method
1. Division by zero
Caused by coefficient value equals zero orvery close to zero
This can be solved by using pivoting technique.
-
8/9/2019 Lecture01 - Gaussian Elimination
16/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 1616
Some Pitfalls of Gauss Elimination Method
2. Round-off errors This may be due to some of the following:
Large numberof equations to be solved due to the fact that everyresult is dependent on previous results.
Errors in early steps will tend to propagate.
Round-off errors may be solved by:
Using more significant figures.
Using fractions instead of decimals.
Always substitute youranswers back into the original system ofequations to check foroccurrence of substantial errors.
-
8/9/2019 Lecture01 - Gaussian Elimination
17/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 1717
Pivoting
This involves the following steps:
1. Determine the largest coefficient available in the column below thepivot element.
2. Switch the rows so that the largest element is the pivot element.This is known as partial pivoting.
3. If columns as well as rows are searched for the largest element
and then switched, the process is called complete pivoting
.
-
8/9/2019 Lecture01 - Gaussian Elimination
18/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 1818
Example 2
Solve the following system of equations
0.0003 x1 + 3.0000 x2 = 2.0001 (1)
1.0000 x1 + 1.0000 x2 = 1.0000 (2)
1. Using nave Gauss elimination
2. Using partial pivoting
-
8/9/2019 Lecture01 - Gaussian Elimination
19/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 1919
Solution of example 2
1. Firstly, lets solve these equations the same way we did in example 1:
Forward elimination:
Multiply equation (1) by 1/0.0003 to get
x1 + 10,000x2 = 6667
Subtract the resulting equation from equation (2) to get
-9999x2 = -6666 x2 = 2/3
Back substitution:0.0003x1 + 3.0000x2 = 2.0001 x1 = 2.0001 3(2/3)
0.0003
-
8/9/2019 Lecture01 - Gaussian Elimination
20/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 2020
Solution of example 2
Now lets check the effects of numberof significant digits
on the result of x1 due to x2:
Significant
figures x2 x1 x1(%)
3 0.667 -3.33 1099
4 0.6667 0.0000 100
5 0.66667 0.30000 10
6 0.666667 0.330000 1
7 0.6666667 0.3330000 0.1
-
8/9/2019 Lecture01 - Gaussian Elimination
21/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 2121
Solution of example 2
2. Secondly, lets solve these equations by applying partial pivoting:
1.0000 x1 + 1.0000 x2 = 1.0000 (1)
0.0003 x1 + 3.0000 x2 = 2.0001 (2)
Forward elimination:
Multiply equation (1) by 0.0003 to get
0.0003 x1 + 0.0003 x2 = 0.0003
Subtract the resulting equation from equation (2) to get
2.9997x2
= 1.9998 x2
= 2/3
Back substitution:
x1 + x2 = 1 x1 = 1 (2/3)
1
-
8/9/2019 Lecture01 - Gaussian Elimination
22/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 2222
Solution of example 2
This case is much less sensitive to the numberof significant
figures on the result of x1 due to x2:
Significant
figures x2 x1 x1(%)
3 0.667 0.333 0.1
4 0.6667 0.3333 0.01
5 0.66667 0.33333 0.001
6 0.666667 0.333333 0.0001
7 0.6666667 0.3333333 0.00001
-
8/9/2019 Lecture01 - Gaussian Elimination
23/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 2323
Scaling
Scaling is necessary when different units are used in the
same system of equations.
Scaling is used to:1. Standardize the size of the coefficients in the system of
equations.
2. Minimize the round-off errors caused by having much larger
coefficients than others.
-
8/9/2019 Lecture01 - Gaussian Elimination
24/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 2424
Example 3
Use three significant figures to solve
2 x1 + 100000 x2 = 10000 (1)
x1 + x2 = 2. (2)
1. Nave Gauss elimination
2. Gauss elimination with scaling and pivoting
3. Gauss elimination without scaling and with pivoting
-
8/9/2019 Lecture01 - Gaussian Elimination
25/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 2525
Solution of example 3
1. Gauss elimination:
Forward elimination
2 x1 + 100000 x2 = 10000 (1)
- 50000 x2 = -5000 (2)
Back substitution
x2 = 0.10 and x1 = 0.00
2. Gauss elimination with scaling and pivoting:
Scaling0.00002 x1 + x2 = 0.1 (1)
x1 + x2 = 2 (2)
-
8/9/2019 Lecture01 - Gaussian Elimination
26/27
Dr. M. HrairiDr. M. Hrairi MTHMTH22122212 -- Computational Methods and StatisticsComputational Methods and Statistics 2626
Solution of example 3
Pivoting
x1 + x2 = 2 (1)
0.00002 x1 + x2 = 0.1 (2)
Forward elimination
x1 + x2 = 2
x2 = 0.1
Back substitution
x1 = 1.90 and x2 = 0.10
-
8/9/2019 Lecture01 - Gaussian Elimination
27/27
Dr. M. HrairiDr. M. Hrairi MTH2212MTH2212 -- Computational Methods and StatisticsComputational Methods and Statistics 2727
Solution of example 3
3. Gauss elimination without scaling and with pivoting of the
original equations:
Pivoting
x1 + x2 = 2.
2 x1 + 100000 x2 = 10000 (1)
Forward elimination
x1 + x2 = 2
100000 x2 = 10000
Back substitutionx1 = 1.90 and x2 = 0.10