5-Module - 2 Lecture PPT - Linear and Nonlinear System of Equations-18!01!2024
5-Module - 2 Lecture PPT - Linear and Nonlinear System of Equations-18!01!2024
Chemical Engineering
• Gauss Jacobi
• Gauss Seidel
-10 -9 -8 - -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10
7 -1 x Convert to equations of the form
-2
-3 y = mx + c
-4
Rewrite the system as two smaller systems, each containing two of the three equations
x – 3y + 6z = 21 x – 3y + 6z = 21
3x + 2y – 5z = –30 2x – 5y + 2z = –6
Eliminate one variable (same variable., Let us take x) in each of the two smaller
systems
(x – 3y + 6z = 21) (-3) (x – 3y + 6z = 21) (-2)
3x + 2y – 5z = –30 2x – 5y + 2z = –6
z=5
y – 10(5) = –48
y – 50 = –48
y=2
Substitute the values of the variables in one of the original equations having three
variables
x – 3(2) + 6(5) = 21
x + 24 = 21
The solution is (–3, 2, 5)
x = –3
Unique Solution
Ill-conditioned systems
Dr. Monash Purushothaman BCHE201L Computational Methods in Chemical Engineering 8
Matrix Notations and Terminology
• Matrix: square matrix,
• Matrix addition
diagonal matrix
• Row vectors
• Matrix subtraction
• Column vectors
• Matrix multiplication
• Symmetric matric
• Determinant of Matrix
• Diagonal matrix
• Inverse of Matrix
• Identity matrix
• Augment of Matrix
x + y+z=2
Rank of a Matrix 4x+2y+z=4 Upper triangular matrix
x - y +z=4
1 1 1 2 1 1 1 2 1 1 1 2
R1 R1 0 2 3 4
4 2 1 4 R2-4R1 0 −2 −3 −4 -R2
1 −1 1 4 R3-R1 0 −2 0 R3-R2 0 0 3 6
2
1
x − 1 + 2 =2 ⇒ x =
Hence the solution is x = 1, y = -1, z = 2.
• If a11 ≠ 0, define m21 = a21 / a11. We can replace (row 2) by {(row 2) – m21 x
(row 1)} to yield
' '
a22 = a22 − m21a12 a23 = a23 − m21a13 b2' = b2 − m21b1
a (1)
22 2x + a (1)
23 3x + + a (1)
2n nx b
= (1)
2
=
a (n − 2)
x
n −1,n −1 n −1 + a (n − 2)
n −1,n nx b
= (n − 2)
n −1
a (n
nn
−1) x = b(n −1)
n n
we can start solving for x's in backward manner
− ∑ j =i +1 aij( i −1) x j
( i −1) n
b ( n −1) b
i
xn = n
( n −1)
xi = ( i −1)
for i = n − 1,n − 2 ,1
a nn a ii
Back Substitution
Q13C1
350 g/s Q33C3
Reactor 1 Reactor 3
Q32C3 Q43C4
Q21C2
Time, t (s) 5 8 12
Solve
10x1 + 7x2 + 8x3 + 7x4 = 32
7x1 + 5x2 + 6x3 + 5x4 = 23
8x1 + 6x2 + 10x3 + 9x4 = 33
7x1 + 5x2 + 9x3 + 10x4 = 31
10 7 8 7 x1 32
7 x 23
5 6 5
A= x = 2 b=
8 6 10 9 x3 33
x4 31
7 5 9 10
for j=1, i=2, K=1 for j=1, i=2, K=2 for j=1, i=2, K=3
10.0000 7.0000 8.0000 7.0000 10.0000 7.0000 8.0000 7.0000 10.0000 7.0000 8.0000 7.0000
0 0.1000 6.0000 5.0000 0 0.1000 6.0000 5.0000 0 0.1000 0.4000 5.0000
8.0000 6.0000 10.0000 9.0000 8.0000 6.0000 10.0000 9.0000 8.0000 6.0000 10.0000 9.0000
7.0000 5.0000 9.0000 10.000 7.0000 5.0000 9.0000 10.000 7.0000 5.0000 9.0000 10.000
for j=2, i=4, K=2 for j=2, i=4, K=3 for j=2, i=4, K=4
10.0000 7.0000 8.0000 7.0000 10.0000 7.0000 8.0000 7.0000 10.0000 7.0000 8.0000 7.0000
0 0.1000 0.40000 0 .1000 0 0.1000 0.40000 0 .10 00 0 0.1000 0.40000 0 .1000
0 0 2.0000 3.0000 0 0 2.0000 3.0000 0 0 2.0000 3.0000
0 0 3.4000 5.1000 0 0 3.0000 5.1000 0 0 3.0000 5.0000
• Round-off error
– Round-off error propagates significantly when we
calculate the solution of a large number of equations.
• Ill-conditioned system
– When the determinant is close to zero
1
x1 + x2 + x3 = x1 + x2 + x3 = 1
x1 + x2 + 2 x3 = 2 x3 = 1 Note that a22 = 0,
x1 + 2 x2 + 2 x3 =
1 x2 + x3 = 0
By interchanging Row 2 and Row 3, we get
x1 + x2 + x3 = 1
This system is non-singular
Upper Triangular
and has a unique solution x2 + x3 = 0 Matrix
x1 = − x2 = x3 = 1
x3 = 1
Dr. Monash Purushothaman BCHE201L Computational Methods in Chemical Engineering 31
Pivoting Strategies
• Avoid division by zero • Minimize the effect of rounding error
1 2 5 −1 7 1 1 2 5 −1 7 1
0 0 33 2 15 2 0 − 8 5 0 10 5
0 − 4 5 6 1 3 0 − 4 5 6 1 3
0 6 25 99 2 4 0 6 25 99 2 4
0 − 8 5 0 10 5 0 0 33 2 15 2
Complete Pivoting
1 2 99 − 1 7 1 1 − 1 99 2 7 1
0 0 33 2 15 2 0 88 25 6 2 4
0 − 4 5 6 1 3 0 6 5 −4 1 3
0 6 25 88 2 4 0 2 33 0 15 2
0 − 8 5 0 10 5 0 0 5 − 8 10 5
2 x1 + 100, 000 x2 =
100, 000
Example:
x1 + 2
x2 =
2 x1 + 100, 000 x2 =
100, 000
−50, 000 x2 =
−50, 000
x2 = 1.00
which can be solved by back substitution for
x1 = 0.00
0.00002 x1 + 1
x2 = x1 + 2
x2 =
After pivoting
x1 + 2
x2 = 0.00002 x1 + 1
x2 =
for i = 1 to n
x(i)=a(i,n+1)/a(i,i);
end
Q13C1
350 g/s Q33C3
Reactor 1 Reactor 3
Q32C3 Q43C4
Q21C2
Now we divide the right hand side vector with the diagonal value, we will get the
Identity matrix, which provides the solution for the unknowns i.e. C1 , C2 , C3 and C4 .
Step 1:
Normalization and elimination of x1:
1.0000 -0.3333 0.0000 0.0000 4.6667
0.0000 45.0000 -45.0000 0.0000 0.0000
0.0000 25.0000 -105.0000 30.0000 -350.0000
0.0000 20.0000 0.0000 -30.0000 -150.0000
Step 2:
Normalization and elimination of x2:
1.0000 0.0000 -0.3333 0.0000 4.6667
0.0000 1.0000 -1.0000 0.0000 0.0000
0.0000 0.0000 -80.0000 30.0000 -350.0000
0.0000 0.0000 20.0000 -30.0000 -150.0000
Step 4:
Normalization and elimination of x4:
1.0000 0.0000 0.0000 0.0000 7.4444
0.0000 1.0000 0.0000 0.0000 8.3333
-0.0000 -0.0000 1.0000 0.0000 8.3333
-0.0000 -0.0000 -0.0000 1.0000 10.5556
Time, t (s) 5 8 12
STEP 2
10 7 8 7 32
0 0.1 0.4 0.1 0.6
0 0 2 3 5
0 0 3 5 8
Note: (N-1) Steps are required to
STEP 3 achieve upper triangular matrix
10 7 8 7 32.000000
0 0.1 0.4 0.1 0.6
0 0 2 3 5
0 0 0 0.5 0.5
STEP 1
1 0.7 0.8 0.7 3.200000
0 0.1 0.4 0.1 0.600000
0 0.4 3.6 3.4 7.400000
0 0.1 3.4 5.1 8.600000
STEP 2
1 0 -2 0 -1.000000
0 1 4 1 6.000000
0 0 2 3 5.000000
0 0 3 5 8.000000
STEP 3
1 0 0 3 4.000000
0 1 0 -5 -4.000000
0 0 1 1.5 2.500000
0 0 0 0.5 0.500000
• Newton’s Method
Iterative Methods are appropriate, when
• the number of equations involved is large (typically of the
order of 100 or more)
• the matrix is sparse (less memory requirements)
Dr. Monash Purushothaman BCHE201L Computational Methods in Chemical Engineering 68
Sparse Matrix
For systems that have coefficient matrices with the
appropriate structure – especially large, sparse systems
(many coefficients whose value is zero) – iterative
techniques may be preferable
4 −1 0 0 −1 0 0 0 0 0 0 0 0 0 0 0 u1 0.08
− 1
4 −1 0 0 −1 0 0 0 0 0 0 0 0 0 0
u 2 0.16
0 −1 4 −1 0 0 −1 0 0 0 0 0 0 0 0 0 u 3 0.36
0 0 −1 4 0 0 0 −1 0 0 0 0 0 0 0 0 u 4 1.64
− 1 0 0 0 4 −1 0 0 −1 0 0 0 0 0 0 0 u 5 0.16
0 −1 0 0 −1 4 −1 0 0 −1 0 0 0 0 0 0 u 6 0.0
0 0 −1 0 0 −1 4 −1 0 0 −1 0 0 0 0 0 u 7 0.0
0 0 0 −1 0 0 −1 4 0 0 0 −1 0 0 0 0 u8 1.0
⋅ =
0 0 0 0 −1 0 0 0 4 −1 0 0 −1 0 0 0 u 9 0.36
0 0 0 0 0 −1 0 0 −1 4 −1 0 0 −1 0 0 u10 0
0 0 0 0 0 0 −1 0 0 −1 4 −1 0 0 −1 0 u11 0
0 0 0 0 0 0 0 −1 0 0 −1 4 0 0 0 − 1 u12 1.0
0 0 0 0 0 0 0 0 −1 0 0 0 4 −1 0 0 u13 1.64
0 0 0 0 0 0 0 0 0 −1 0 0 −1 4 −1 0 u 1.0
14
0 0 0 0 0 0 0 0 0 0 −1 0 0 −1 4 − 1 u15 1.0
0 0 0 0 0 0 0 0 0 0 0 −1 0 0 −1 4 u16 2.0
• Stopping criteria?
n
bi − ∑ aij x j
j =1
j ≠i
General form for any row ‘i’ xi
= for =i 1, 2, …, n.
aii
o If you have “n” number of equations you have to guess “n” number of initial
guesses for the unknowns
Note
• It is not necessary all the unknowns have same initial guess values
• In general, the initial values of the initial guesses is assumed to be “0”
• If the Physical nature of the problem is known, one can assume initial guess
close to the approximate solution (to reduce the number of iterations)
x inew − x iold
o Calculate the Absolute Relative Approximate Error εa = new
×100
i
xi
o Stop the iteration, when the absolute relative approximate error is less than a
pre-specified tolerance for all unknowns
Initial guesses
30 g/s
14 m3/s (c2) 17 m3/s (c3)
5 m3/s (c2)
200 g/s R3
R2 2 m3/s (c3)
R1
500 g/s 7 m3/s (c1)
Thank you