CPNM Lecture 14 Solutions To Linear Simultaneous Equations
CPNM Lecture 14 Solutions To Linear Simultaneous Equations
Equations
Jadavpur University
2023
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 1 / 34
Linear Systems I
a1 x1 + a2 x2 + . . . + an xn = b
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 2 / 34
Linear Systems II
The system of linear equations can be written in matrix form
AX = B (2)
where,
a11 a12 a13 . . . a1n x1 b1
a21 a22 a23 . . . a2n x2 b2
A= . .. , X = .. , and B = ..
.. .. ..
.. . . . . . .
an1 an2 an3 . . . ann xn bn
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 4 / 34
Naive Gaussian Elimination I
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 6 / 34
Naive Gaussian Elimination III
Back Substitution
bnn−1
Last row can be solved as xn = n−1
ann
The result can be back-substituted into the (n − 1)th row to solve for
n−2 n−2
xn−1 = (bn−1 − an−1,n xn )/an−1,n−1
...
n
P
x1 = (b1 − a1j xj )/a11
j=2
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 7 / 34
Naive Gaussian Elimination IV
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 8 / 34
Naive Gaussian Elimination V
Drawbacks
Division by Zero
During both elimination and back-substitution phase division by zero
may occur
Pivoting technique partially avoids these problem
Round-Off Errors
Occurs due to limited significant digits
Ill-Conditioned Systems
Small changes in coefficients result in large changes in the solution
Implication ⇒ wide range of answers can approximately satisfy the
equations
Singular Systems
Determinant of a singular system is zero
After elimination stage the algorithm must check whether a zero
diagonal element is created; if so, abort
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 9 / 34
Example of Gaussian Elimination I
Use Gaussian Elimination to solve
2x + y + z = 10
3x + 2y + 3z = 18
x + 4y + 9z = 16
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 11 / 34
Gaussian Elimination Algorithm I
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 12 / 34
Gaussian Elimination Algorithm II
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 13 / 34
Gauss-Jordon Elimination I
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 14 / 34
Gauss-Jordon Elimination II
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 15 / 34
Gauss-Jordon Elimination III
Algorithm 3 Gauss-Jordon Method
1: for i = 1 to n in steps of 1 do
2: j =i
3: while a[i][i] == 0 & j ≤ n do
4: Interchange i and (j + 1)th row of matrix a
5: j =j +1
6: end while
7: f = a[i][i]
8: for k = i to n + 1 in steps of 1 do
9: a[i][k] = a[i][k]/f
10: end for
11: for k = 1 to n in steps of 1 do
12: if k ̸= i then
13: f = a[k][i]/a[i][i]
14: for p = i to n + 1 in steps of 1 do
15: a[k][p] = a[k][p] − f ∗ a[i][p]
16: end for
17: end if
18: end for
19: end for
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 16 / 34
Example of Gauss-Jordon Elimination I
Use Gauss-Jordon Elimination to solve
x +y +z =5
2x + 3y + 5z = 8
4x + 5z = 2
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 18 / 34
Example of Gauss-Jordon Elimination III
1 0 −2 7
0 1 3 −2
0 0 13 −26
R3
Dividing R3 by it’s pivot element a33 = 13 or [R3 ← 13 ]
1 0 −2 7
0 1 3 −2
0 0 1 −2
Eliminating third variable z from equation 1 and 2 by performing
transformations [R1 ← R1 − (−2)R3 ] and [R2 ← R2 − 3R2 ]
1 0 0 3
0 1 0 4
0 0 1 −2
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 19 / 34
Example of Gauss-Jordon Elimination IV
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 20 / 34
Matrix Inversion Using Gauss-Jordon Elimination I
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 21 / 34
Solution of Linear Systems - Iterative Method I
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 22 / 34
Solution of Linear Systems - Iterative Method II
We can rewrite the equations as
x1 = ab111 − aa11
12
x2 − a13
a11 x3 − ... − a1n
a11 xn
b a a23 a2n
x2 = a222 − a22 21
x1 − a22 x3 − ... − a22 xn
.. (8)
.
an,(n−1)
bn an1 an2
− ann x1 − ann x2 − . . . −
x =
n ann ann xn−1
(1) (1) (1) (1)
Suppose the vector X = [x1 , x2 , x3 , . . . , xn ] be a first
approximation to the unknowns x1 , x2 , x3 , . . . , xn
So, the second approximation is obtained as
(2) (1) 13 (1) (1)
x1 = ab111 − aa12 x − aa11
11 2
x3 − . . . − aa1n
11
xn
x (2) = b2 − a21 x (1) − a23 x (1) − . . . − a2n xn(1)
2 a22 a22 1 a22 3 a22
.. (9)
.
(2)
bn an1 (1) an2 (1) a (1)
xn = ann − ann x1 − ann x2 − . . . − n,(n−1) ann xn−1
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 23 / 34
Solution of Linear Systems - Iterative Method III
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 24 / 34
Jacobi’s Method I
provided aii ̸= 0
Also known as method of simultaneous displacements
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 25 / 34
Jacobi’s Method II
input a → augmented matrix of order n × (n + 1), e → allowed relative error in the result,
maxit → the maximum number of iterations
output x → solution vector
1: for i = 1 to n in steps of 1 do
2: x[i] = 0
3: end for
4: for iter = 1 to maxit in steps of 1 do
5: big = 0
6: for i = 1 to n in steps of 1 do
7: sum = 0
8: for j = 1 to n in steps of 1 do
9: if j ̸= i then
10: sum = sum + a[i][j] ∗ x[j]
11: end if
12: end for
13: temp = (a[i][n + 1] − sum)/a[i][i]
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 26 / 34
Jacobi’s Method III
14: relerror =| (x[i] − temp)/temp |
15: if relerror > big then
16: big = relerror
17: end if
18: x ′ [i] = temp
19: end for
20: for i = 1 to n in steps of 1 do
21: x[i] = x ′ [i]
22: end for
23: if big ≤ e then
24: Write ”Converges to a solution”
25: Stop
26: end if
27: end for
28: Write ”Does not converge in maxit number of iterations”
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 27 / 34
Jacobi’s Method IV
The Jacobi iterative method works fine with well-conditioned linear systems
If the linear system is ill-conditioned, it is most probably that the Jacobi
method will fail to converge
The Jacobi method can generally be used for solving linear systems in which
the coefficient matrix is diagonally dominant
For each row, the absolute value of the diagonal term is greater than the
sum of absolute values of other terms
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 28 / 34
Gauss-Seidel Method I
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 29 / 34
Gauss-Seidel Method II
input a → augmented matrix of order n × (n + 1), e → allowed relative error in the result,
maxit → the maximum number of iterations
output x → solution vector
1: for i = 1 to n in steps of 1 do
2: x[i] = 0
3: end for
4: for iter = 1 to maxit in steps of 1 do
5: big = 0
6: for i = 1 to n in steps of 1 do
7: sum = 0
8: for j = 1 to n in steps of 1 do
9: if j ̸= i then
10: sum = sum + a[i][j] ∗ x[j]
11: end if
12: end for
13: temp = (a[i][n + 1] − sum)/a[i][i]
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 30 / 34
Gauss-Seidel Method III
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 31 / 34
Example of Iterative Method I
Use Jacobi’s / Gauss-Seidel Method to solve
10x1 − 2x2 − x3 − x4 = 3
−2x1 + 10x2 − x3 − x4 = 15
−x1 − x2 + 10x3 2x4 = 27
−x1 − x2 − 2x3 + 10x4 = −9
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 33 / 34
Example of Iterative Method III
n x1 x2 x3 x4
1 0.300000 1.560000 2.886000 -0.136800
2 0.886920 1.952304 2.956562 -0.024765
3 0.983641 1.989908 2.992402 -0.004165
4 0.996805 1.998185 2.998666 -0.000768
5 0.999427 1.999675 2.999757 -0.000138
6 0.999897 1.999941 2.999956 -0.000025
7 0.999981 1.999989 2.999992 -0.000005
8 0.999997 1.999998 2.999999 -0.000001
9 0.999999 2.000000 3.000000 -0.000000
10 1.000000 2.000000 3.000000 -0.000000
Mridul Sankar Barik (Jadavpur University) CPNM Lecture 14 - Solutions to Linear Simultaneous Equations
2023 34 / 34