2 - Solution of Simultaneous Linear Equations - 26 Pgs New
2 - Solution of Simultaneous Linear Equations - 26 Pgs New
2 - Solution of Simultaneous Linear Equations - 26 Pgs New
1. Graphical Method
For two equations (n = 2):
a11 x1 a12 x2 b1
a21 x1 a22 x2 b2
Solve both equations for x 2 : the intersection of the lines presents the solution.
a b
x2 11 x1 1 x2 (slope)x1 intercept
a12 a12
a b
x2 21 x1 2
a22 a22
3x1 2x 2 18
Solve:
- x1 2x 2 2
6
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Steps of solution:
𝑎11 ⋯ 𝑎1𝑛
1. Form the coefficients matrix [𝑎𝑖𝑗 ] = [ ⋮ ⋱ ⋮ ] and the right-hand vector
𝑎𝑛1 ⋯ 𝑎𝑛𝑛
𝑏1
{𝑏𝑖 } = { ⋮ }
𝑏𝑛
2. Evaluate det.[A] using any method. If det.[A] = 0, then the set of equations has
no solution and the [A] is called singular; otherwise proceed to the next step.
3. When det.[A] ≠ 0, evaluate det.[𝐴𝑗 ] by replacing the jth. matrix with column
vector {𝑏𝑖 }.
4. Repeat step (3) for j = 1, 2, ……….., n.
5. Solve for unknowns 𝑥𝑗 by dividing det.[𝐴𝑗 ] by det.[A].
𝑑𝑒𝑡.[𝐴𝑗 ]
𝑥𝑗 = , j = 1, 2, …….…., n
𝑑𝑒𝑡.[𝐴]
Or
𝑏1 𝑎12 𝑎13 𝑎11 𝑏1 𝑎13 𝑎11 𝑎12 𝑏1
|𝑏2 𝑎22 𝑎23 | |𝑎21 𝑏2 𝑎23 | |𝑎21 𝑎22 𝑏2 |
𝑏3 𝑎32 𝑎33 𝑎31 𝑏3 𝑎33 𝑎31 𝑎32 𝑏3
𝑥1 = |𝐴|
, 𝑥2 = |𝐴|
, 𝑥3 = |𝐴|
30 2 3 8 30 3 8 2 30
1 9 2 1 1 2 1 9 1
31 3 6 842 2 31 6 421 2 3 31 1684
x1 2 x2 1 x3 4
421 421 421 421 421 421
8
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
(2) 𝑥 + 3𝑦 + 𝑧 = 5
2𝑥 + 𝑦 − 𝑧 = 3
𝑥 − 3𝑦 − 3𝑧 = 1 Ans. 𝑥 = −8 , 𝑦 = 8 and 𝑧 = −11
Expand determinants using pivotal condensation method.
3. Inverse Method
This method is also impractical for solution of large system of equations. First of
all, the equations to be solved must be arranged so that the diagonal coefficients are
dominant.
or 𝑥 = 𝐴−1 . 𝑏 ………………………………………………(2)
where,
𝑐11 𝑐12 ⋯ 𝑐1𝑛 T
𝐴𝑑𝑗 [𝐴] 1 𝑐21 𝑐22 ⋯ 𝑐2𝑛
𝐴−1 = = [ ⋮ ⋮ ⋯ ⋮ ]
𝑑𝑒𝑡.[𝐴] 𝑑𝑒𝑡.[𝐴]
𝑐𝑛1 𝑐𝑛2 ⋯ 𝑐𝑛𝑛
9
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
After multiplying the minors by determinant of the elements (deleting the ith. row and jth.
column of matrix A) to obtain the cofactors. Then, transpose of cofactor matrix is called
𝑐11 𝑐21 𝑐31
Adjoint matrix: 𝐴𝑑𝑗 [𝐴] = [𝐶𝑖𝑗 ] = [𝑐12 𝑐22 𝑐32 ]
T
10
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
−60(30)−3(1)+31(31)
For example: 𝑥1 = =2
−421
(2) 𝑥 − 2𝑦 + 3𝑧 = 2
2𝑥 − 3𝑧 = 3
𝑥+ 𝑦 + 𝑧 =0 Ans. 𝑥 = 21/19 , 𝑦 = −16/19 and 𝑧 = −5/19
4. Elimination of unknowns
The basic strategy is to successively solve one of the equations of the set for one
of the unknowns and to eliminate that variable from the remaining equations by
substitution.
The elimination of unknowns can be extended to large systems with more than
two or three equations. However, the method becomes extremely tedious to solve
by hand.
11
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
(b) Indirect or Iterative Methods: used when direct methods are incapable or
may be slow:
Begin with an approximate solution and obtain an improved one with each step
of the iterations,
Require an infinite number of steps to obtain an exact solution in the absence
of round off errors,
The accuracy of solution depends on number of iterations performed.
1. Jacobi's iteration method, and
2. Gauss−Seidel iteration method.
In some cases, direct and indirect methods are combined; first we may use a direct
method and then the solution may be improved by using indirect methods.
12
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Direct Methods:
1. Gauss − Elimination Method:
It is the most popular and efficient method for solving (n × n) system of equations. It consists
of a series of elementary row operations to transform the original matrix [A] into either:
An upper triangular matrix, then by back substitution, the unknowns; 𝑥𝑛 , …., …𝑥2 ,
𝑥1 can be determined, or
Lower triangular matrix, then by forward substitution, the unknowns; 𝑥1 , 𝑥2 , ………,
𝑥𝑛 are directly determined.
Notes:
1. Find the entry in the 1st. column with the largest absolute value. This entry is called the pivot.
2. Perform a row interchange, if necessary, so that the pivot is in the 1st. row.
3. Divide the 1st. row by the pivot. (This step is unnecessary if the pivot is 1.0)
4. Use elementary row operations to reduce the remaining entries in the 1st. column to zero’s.
5. Continue this process for other columns and @ each stage the remaining equations may
require rearranging to avoid a zero division in the 𝑎𝑖𝑗 position,
𝑛3
6. In this method, no. of multiplications and divisions = +𝑂(𝑛2 ). for example, for 10×10
3
10×10×10
eqs., no. of operations involved ≈ ≈ 333
3
13
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Now by back substitution, the unknowns (𝑥1 , 𝑥2 , and 𝑥3 ) can be determined as:
𝑥3 = 3
𝑥2 − 0.642(3) = 0.071 → 𝑥2 = 2
𝑥1 1
𝑥1 − 0.5(2) + 0.25(3) = 0.75 → 𝑥1 = 1 ∴ 𝑥
{ 2 } = {2}
𝑥3 3
𝑛3
4. The total no. of required operations by Gauss-Jordan method is = +𝑂(𝑛2 )
2
𝑛3
compared with +𝑂(𝑛2 ) operations required for Gauss-Elimination method.
3
2 −4 6 5 𝑅1 /2 →
[1 3 −7 2 ]
7 5 9 4
1 −2 3 2.5
[1 3 −7 2 ] −𝑅1 + 𝑅2 →
7 5 9 4 −7𝑅1 + 𝑅3 →
1 −2 3 2.5
[0 5 −10 −0.5 ] 𝑅2 /5 →
0 19 −12 −13.5
1 −2 3 2.5 2𝑅2 + 𝑅1 →
[0 1 −2 −0.1 ]
0 19 −12 −13.5 −19𝑅2 + 𝑅3 →
1 0 −1 2.3
[0 1 −2 −0.1 ]
0 0 26 −11.6 𝑅3 /26 →
1 0 −1 2.3 𝑅3 + 𝑅1 →
[0 1 −2 −0.1 ] 2𝑅3 + 𝑅2 →
0 0 1 −0.45
1 0 0 1.85 𝑥1 1.85
[0 1 0 −0.99 ] ∴ {𝑥2 } = { −0.99 }
0 0 1 −0.45 𝑥3 −0.45
Note: To reduce round off errors take four or more numbers after decimals.
15
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Example (7): Find the inverse matrix 𝐀−𝟏 of the following system of linear
equations by Gauss−Jordan Elimination method.
2 −4 6 1 0 0 𝑅1 /2 →
[1 3 −7 0 1 0 ]
7 5 9 0 0 1
1 −2 3 0.5 0 0
[1 3 −7 0 1 0 ] −𝑅1 + 𝑅2 →
7 5 9 0 0 1 −7𝑅1 + 𝑅3 →
1 −2 3 0.5 0 0
[0 5 −10 −0.5 1 0 ] 𝑅2 /5 →
0 19 −12 −3.5 0 1
1 −2 3 0.5 0 0 2𝑅2 + 𝑅1 →
[0 1 −2 −0.1 0.2 0 ]
0 19 −12 −3.5 0 1 −19𝑅2 + 𝑅3 →
1 0 −1 0.3 0.4 0
[0 1 −2 −0.1 0.2 0 ]
0 0 26 −1.6 −3.8 1 𝑅3 /26 →
1 0 −1 0.3 0.4 0 𝑅3 + 𝑅1 →
[0 1 −2 −0.1 0.2 0 ] 2𝑅3 + 𝑅2 →
0 0 1 −0.061 −0.146 0.038
16
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Round-off errors. These errors occur due to that every result is dependent on previous
results. Consequently, an error in early steps will tend to propagate and cause errors
in subsequent steps. Therefore, a good idea to substitute your answers back into the
original equations and check whether a substantial error has occurred.
Ill-conditioned systems are those where small changes in coefficients result in large
changes in solution. Also, it happens when two or more equations are nearly identical,
resulting a wide ranges of answers to satisfy the equations.
Important Observations
An ill-conditioned system is one with a determinant close to zero
If determinant D=0 then there are infinite solutions singular system
17
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Pivoting. If a pivot element is zero, elimination step leads to division by zero. The
same problem may arise, when the pivot element is close to zero. This problem can be
avoided by:
Partial pivoting. Switching the rows so that the largest element is the pivot element.
Complete pivoting. Searching for the largest element in all rows and columns then
switching. But, this pivoting is rarely used because switching columns changes the
order of the x’s.
x1 10000 x2 6667 which can be used to eliminate x1 from the 2nd equation:
9999 x2 6666 x2 2 / 3
This result can be substituted back into the 1st. equation to evaluate x1 :
2.0001 3(2 / 3)
x1
0.0003
However, the value for x1 is highly dependent on the number of significant digits
after decimals carried in the computation as shown in Table below:
Significant digits x2 x1 % relative error for 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
18
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
If the equations are solved in reverse order, the row with the large pivot element is
normalized. The equations are
Comparing the results in this case with those of Example (8) shows that a pivot
strategy is much more satisfactory.
Homework # 3:
2 𝑥2 + 4𝑥3 = 6
4𝑥1 + 𝑥2 − 3𝑥3 = 1
3𝑥1 − 8 𝑥2 + 2𝑥3 = 2 Ans. 𝑥3 = 1.264 , 𝑥2 = 0.472 and 𝑥1 = 1.080
19
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
3. LU − Decomposition Method:
∴ 𝐴. 𝑥 = 𝐿𝑈𝑥 = 𝑏 ………………………………………………………(1)
In details:
𝑎11 𝑎12 𝑎13 𝑥1 𝑙11 0 0 𝑢11 𝑢12 𝑢13
[𝑎21 𝑎22 𝑎23 ] {𝑥2 } = [𝑙21 𝑙22 0 ][ 0 𝑢22 𝑢23 ]
𝑎31 𝑎32 𝑎33 𝑥3 𝑙31 𝑙32 𝑙33 0 0 𝑢33
Total number of unknown = 𝑛2 + 𝑛
To solve Eq.(1) for a given A and b, the solution is done in two logical steps:
1. First, let 𝑼. 𝒙 = 𝒚 and find y from the equation: L y = b for y.
(starting from top because L is a lower triangular matrix).
𝑙11 0 0 𝑦1 𝑏1
[𝑙21 𝑙22 0 ] {𝑦2 } = {𝑏2 }
𝑙31 𝑙32 𝑙33 𝑦3 𝑏3
2. Second, to find x use: Ux = y for x.
(starting from bottom because U is an upper triangular matrix).
𝑢11 𝑢12 𝑢13 𝑥1 𝑦1
[ 0 𝑢22 𝑢𝑎23 ] {𝑥2 } = {𝑦2 }
0 0 𝑎33 𝑥3 𝑦3
20
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Solution:
𝑨. 𝒙 = 𝒃
8 2 3 𝑥1 30
𝑥
[1 −9 2] { 2 } = { 1 }
2 3 6 𝑥3 31
Factorize [A] into L and U: 𝐴 = 𝐿 . 𝑈 and set 𝑙𝑖𝑖 or 𝑢𝑖𝑖 = 1 in diagonal of L
or in diagonal of U (Take 𝑙𝑖𝑖 = 1), then
A L LT or A U UT
Solution is also in two stages as before. But, there is a danger that complex
numbers will appear in (L or U) especially when the diagonal coefficients of A
are small or negative. Therefore, either continue the solution and get the results
or try to factorize A into:
22
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
A L D LT or A U D UT
(2) If A is not symmetric (AT ≠ A), then multiply both sides of A x = B by AT.
Thus A T A x A TB
and use C L LT or C U UT
or C L D LT or C U D UT
2 0.5 x1 y1
Let
0 3.25 x2 y2
23
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Then
2 0 y1 2.0
0.5 3.25 y2 5.0
This gives
y1 1.0
0.5 y1 3.25 y2 5.0 y2 5.5 / 3.25
Then
2 0.5 x1 1.0
0 3.25 x2 5.5 / 3.25
Let
2 0.5 x1 y1
0 3.25 x2 y2
Then
2 0 y1 2.0
0.5 3.25 y2 5.0
This gives
y1 1.0
0.5 y1 3.25 y2 5.0 y2 5.5 / 3.25
Then
2 0.5 x1
1.0
0 3.25 x2 5.5 / 3.25
Thus,
1.0 0.5(1.692)
x2 1.692 and x1 0.077 (as before)
2
24
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Write 4 1 1 0 11
d 0 1 l21
(ii) By using A L D LT :
1 3 l21 1 0 d 22 0 1
(1) 𝑥1 + 4 𝑥2 = 10
2𝑥1 + 10 𝑥2 − 4𝑥3 = 7
𝑥2 + 8𝑥3 − 𝑥4 = 6
𝑥3 − 6𝑥4 = 4
Ans. 𝑥4 = −0.466, 𝑥3 = 1.203, 𝑥2 = −4.093, and 𝑥1 = 26.373
(2) 2 𝑥1 + 𝑥2 + 𝑥3 = 7
𝑥1 + 2𝑥2 + 𝑥3 = 8
𝑥1 + 𝑥2 + 2𝑥3 = 9
Ans. 𝑥3 = 3 , 𝑥2 = 2 and 𝑥1 = 1
25
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
First, to eliminate a21 and a31 from col.(1), pre-multiply the given matrix by the 1st.
reducing matrix [R1]:
1 0 0
R1 a 21/a11 1 0
a /a 1
31 11 0
1 0 0 a11 a12 a13 b1 a11 a12 a13 b1
Thus, a 21/a11 1 0 a 21 a 22 a 23 b2 0 a 22 a 23 b2
a /a 1 a a 33 b3 0 a 32 a 33 b3
31 11 0 31 a 32
from col.(2), pre-multiply the new matrix by the 2nd.
Second, to eliminate a32
reducing matrix [R2]:
1 0 0
R1 2 1 0
3 0 1
1 0 0 1 1 1 6 1 1 1 6
2 1 0 2 1 2 2 0 1 4 14
3 0 1 3 2 1 2 0 5 2 16
1 0 0
R 2 0 1 0
0 5 1
1 0 0 1 1 1 6 1 1 1 6
0 1 0 0 1 4 14 0 1 4 14
0 5 1 0 5 2 16 0 0 18 54
54
x3 3
18
x2 14 4(3) 2
x1 6 3 2 1
Ans. 𝑥4 = 4, 𝑥3 = 3, 𝑥2 = 2, and 𝑥1 = 1
27
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Indirect Methods:
1. Jacobi's iteration method, and
2. Gauss−Seidel iteration method.
Rearrange the equations so that the diagonal coefficient is greater than other
coefficients in any equation (i.e., |𝑎𝑖𝑖 | > ∑|𝑎𝑖𝑗 | for i = 1, 2, ……..n
j = 1, 2, ……..n
28
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
Check the diagonal coefficients and determine whether the iterative procedure is
suitable. Thus:-
|5| > |−2| + |1| → 5 > 3 (O.K.)
𝒙𝟏 0 0.8 0.25 1.14 1.24 1.02 0.92 0.98 1.02 1.01 0.99
𝒙𝟐 0 0.75 2.68 2.53 1.89 1.79 1.99 2.07 2.02 1.98 1.99
𝒙𝟑 0 4.25 3.68 2.85 2.70 2.99 3.10 3.02 2.97 2.98 3.01
𝑥1 1
The exact solution for this system of equations is {𝑥2 } = {2}
𝑥3 3
29
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
This method converges faster than Jacobi’s method. In this method, start with initial
(0) (0) (0) (1) (1) (1)
estimates (𝑥1 , 𝑥2 , 𝑥3 ) = 0, 0, 0 to compute a new set (𝑥1 , 𝑥2 , 𝑥3 ). But, the new
computed value calculated first should replace the old one before computing all other
new values. Then, reuse the new estimated values as initial estimates to find the next
(1) (1) (1)
(𝑥1 , 𝑥2 , 𝑥3 ) and so on.
5𝑥1 − 2𝑥2 + 𝑥3 = 4
𝑥1 + 4𝑥2 − 2𝑥3 = 3
𝑥1 + 2𝑥2 + 4𝑥3 = 17
Solution:
After checking the diagonal coefficients and determining whether the iterative
procedure is suitable.
This process is continued until successive values of each vector are sufficiently
close in magnitude as shown in the following table:
30
Numerical Methods / Solution of Simultaneous Linear Equations Assist. Prof. Dr. Rafi' M. S.
k
𝒙
0 1 2 3 4 5 6 7
Note that the results obtained in (5) iterations are more accurate than those
obtained in (10) iterations using Jacobi’s method.
𝑥1 1
The exact solution for this system of equations is {𝑥2 } = {2}
𝑥3 3
(1) 5𝑥1 − 𝑥2 − 𝑥3 = 2
𝑥1 + 𝑥2 + 4𝑥3 = 10
𝑥1 − 3𝑥2 + 𝑥3 = 0
𝑥1 1
Ans. {𝑥2 } = {1}
𝑥3 2
(2) 5𝑥 − 3𝑦 − 2𝑧 = 9
2𝑥 − 4𝑦 + 𝑧 = 8
𝑥 + 2𝑦 + 4𝑧 = 22
𝑥 4
Ans. {𝑦} = {1}
𝑧 4
31