Professional Documents
Culture Documents
Lecture - 9: System of Linear Algebraic Equations Direct Methods: Gauss Elimination
Lecture - 9: System of Linear Algebraic Equations Direct Methods: Gauss Elimination
Lecture - 9: System of Linear Algebraic Equations Direct Methods: Gauss Elimination
Hyderabad Campus
Lecture -9:
SYSTEM of LINEAR ALGEBRAIC EQUATIONS
Direct Methods: Gauss Elimination
1
Solving Systems of Equations
– Graphical method
– Cramer’s rule
– Method of elimination
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-2
Graphical Method
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-3
Graphical Method
c) b)
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-4
Determinants and Cramer’s Rule
a21 a23
a11 a12 a13 D12 a21 a33 a31 a23
A a21 a22 a23 a31 a33
a21 a22
a31 a32 a33 D13 a21 a32 a31 a22
a31 a32
a22 a23 a21 a23 a21 a22
Determinant of A D a11 a12 a13
a32 a33 a31 a33 a31 a32
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-6
Gauss Elimination
x1 - x2 + x3 = 6
0 7x2 - x3 = -9
0 0 -(4/7)x3=-(8/7)
Solve using BACK SUBSTITUTION: x3 = 2 x2=-1 x1 =3
0
0 0
0 0 0
0 0 0 0
0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-8
Back Substitution
2x2 – 3x3 = 0
x3 = 2 2x3 = 4
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-9
Back Substitution
– 2x1 –3x2 = 3
x2 = 3 2x2 = 6
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-10
Back Substitution
1x0 +1x1 = 3
x1 = –6 – 2x1 = 12
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-11
Back Substitution
1x0 +1x1 = 3
x1 = –6 – 2x1 = 12
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-12
x0 = 9 1x0 = 9
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-13
Forward Elimination
a ji
a ji a ji aii 0
aii
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-14
Forward Elimination
M
U
L
T
I
P 4x0 +6x1 +2x2 – 2x3 = 8
L
I
E
R
S
-(2/4) 2x0 +5x2 – 2x3 = 4
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-15
Forward Elimination
M
U
L
T
I 4x0 +6x1 +2x2 – 2x3 = 8
P
L
I
E
R – 3x1 +4x2 – 1x3 = 0
S
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-16
Forward Elimination
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-17
Forward Elimination
1x2 +1x3 = 9
3x3 = 6
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-18
Operation count in
Forward Elimination
b11
2n 0 b22
2n 0 0 b33
2n 0 0 0 b44
2n 0 0 0 0 b55
2n 0 0 0 0 0 b66
2n 0 0 0 0 0 0 b77
2n 0 0 0 0 0 0 0 b66
2n 0 0 0 0 0 0 0 0 b66
TOTAL
1st column: 2n(n-1) 2n2 2(n-1)2 2(n-2)2 …….
TOTAL # of Operations for FORWARD ELIM INATION :
n
2n 2(n 1) ... 2 * (2) 2 * (1) 2 i 2
2 2 2 2
i 1
n(n 1)(2n 1)
2
6
O(n 3 )
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-19
Pitfalls of Elimination Methods
Division by zero
It is possible that during both elimination and back-substitution phases a
division by zero can occur.
For example:
2x2 + 3x3 = 8 0 2 3
4x1 + 6x2 + 7x3 = -3 A= 4 6 7
2x1 + x2 + 6x3 = 5 2 1 6
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-20
Pitfalls (cont.)
Round-off errors
• It is also a good idea to substitute your results back into the original
equations and check whether a substantial error has occurred.
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-21
Pitfalls (cont.)
ill-conditioned systems - small changes in coefficients result in large
changes in the solution. Alternatively, a wide range of answers can
approximately satisfy the equations.
(Well-conditioned systems – small changes in coefficients result in small
changes in the solution)
Problem: Since round off errors can induce small changes in the coefficients, these
changes can lead to large solution errors in ill-conditioned systems.
Example: b1 a12 10 2
x1 + 2x2 = 10
b2 a22 10.4 2 2(10) 2(10.4)
1.1x1 + 2x2 = 10.4 x1 4 x2 3
D 1(2) 2(1.1) 0.2
x1 + 2x2 = 10 b1 a12 10 2
1.05x1 + 2x2 = 10.4 b2 a22 10.4 2 2(10) 2(10.4)
x1 8 x2 1
D 1(2) 2(1.05) 0.1
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-22
ill-conditioned systems (cont.) –
• Surprisingly, substitution of the erroneous values, x1=8 and x2=1, into the original
equation will not reveal their incorrect nature clearly:
x1 + 2x2 = 10 8+2(1) = 10 (the same!)
1.1x1 + 2x2 = 10.4 1.1(8)+2(1)=10.8 (close!)
IMPORTANT OBSERVATION:
An ill-conditioned system is one with a determinant close to zero
• If determinant D=0 then there are infinitely many solutions singular system
• Scaling (multiplying the coefficients with the same value) does not change the
equations but changes the value of the determinant in a significant way.
However, it does not change the ill-conditioned state of the equations!
DANGER! It may hide the fact that the system is ill-conditioned!!
• One way to find out: change the coefficients slightly and recompute & compare
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-23
Techniques for Improving Solutions
• Use of more significant figures – double precision arithmetic
• Pivoting
If a pivot element is zero, normalization step leads to division by zero. The
same problem may arise, when the pivot element is close to zero. Problem
can be avoided:
– Pivoting
Switching the rows below so that the largest element is the pivot element.
– Partial pivoting
• Searching for the largest element in all rows and columns then switching.
• This is rarely used because switching columns changes the order of x’s
and adds significant complexity and overhead costly
• Scaling
– used to reduce the round-off errors and improve accuracy
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-24
Gauss-Jordan Elimination
a11 0 0 0 0
0 0 0 0 b11
0 x22 0 0 0 0 0 0 0 b22
x33 0 0 0 0 0 0 b33
0 0
0 0 0 x44 0 0 0 0 0 b44
x55 0 0 0 0
0 0 0 0 b55
0 0 0 0 0 x66 0 0 0 b66
0 0 0 0 0 0 x77 0 0 b77
0 0 0 0 0 0 0 x88 0
b66
0 0 0 0 0 0 0 0 x99 b66
CHE F242 Numerical Methods for Chemical Engineers, BITS, Pilani-Hyderabad Campus P-25
Gauss-Jordan Elimination: Example
1 1 2 x1 8 1 1 2| 8
1 2 3 x 1 Augmented Matrix : 1 2 3 | 1
2
3 7 4 x3 10 3 7 4 |10
1 1 2 | 8 Scaling R2: 1 1 2 | 8
R2 R2 - (-1)R1 0 1 5 | 9 R2 R2/(-1) 0 1 5| 9
R3 R3 - ( 3)R1 0 4 2| 14 0 4 2| 14
R1 R1 - (1)R2 1 0 7 | 17 1 0 7 | 17
0 1 5 | 9 Scaling R3: 0 1 5 | 9
R3 R3-(4)R2 0 0 18 | 22 R3 R3/(18) 0 0 1 |11 / 9