Professional Documents
Culture Documents
Part4 Linear Equations
Part4 Linear Equations
Computing Methods in
Engineering
SOLUTION OF LINEAR
EQUATIONS
1.1 Scope
The equation in which the degree of the variable is one (largest degree) is called
a linear equation, and the equation with more than one degree of the variables
(the largest degree) is called a system of equations or a set of equations. For
example, containing unknowns ( x1 , x 2 ,…, x n ), the system of linear equations
consisting of n linear equations can be written in general form as.
a11 x1 + a12 x2 + a13 x3 + ... + a1n xn = b1
a21 x1 + a22 x2 + a23 x3 + ... + a2 n xn = b2
a31 x1 + a32 x2 + a33 x3 + ... + a3n xn = b3 (1.1)
...
an1 x1 + an 2 x2 + an3 x3 + ... + ann xn = bn
Methods
Êngineering Problems Numerical- Equation System
Computational Methods
-Differential Equation -Finite Difference -Linear Equation System
-Finete Element -Non-linear Equation
-Finite Volume System
-etc.
-Interal Equation
Figure 1.1: Solution of differential and integral equations by converting them to
linear or nonlinear system of equations.
Below are the differential equations of some problems in the field of mechanics
and heat conduction and their equivalent forms expressed as a system of linear
equations for solution.
Beam Bending:
The bending differential equation and boundary conditions (both ends simply
supported) can be expressed as follows for a beam of width b, height h, and length
L, which has a modulus of elasticity E shown in Figure 1.2, under the distributed
d 4 w( x) bh 3
load q:Differential Equation: EI = q ( x) (I = )
dx 4 12
d 2w
Boundary Conditions: w(0) = 0 , M (0) = EI 2 (0) = 0 , w( L) = 0 ,
dx
d 2w
M ( L) = EI ( L) = 0
dx 2
The deflection values of the beam can be obtained for the nodal points in Figure
1.3 with the Finite Difference method, one of the numerical methods oftenly
utilized.
Figure 1.3: Discretization of the beam for the solution with the Finite Difference
method.
The unknown deflection values of the discretized beam as above can be expressed
in matrix form as a system of linear equations as follows
q3 (x )4
1 − 4 6 − 4 1 0 0 w1 EI
0 1 − 4 6 − 4 1 0 w q 4 (x )4
2
0 0 1 − 4 6 − 4 1 w3 EI 4
q5 (x )
0 1 0 0 0 0 0 w4 = EI
1 − 2 1 0 0 0 0 w5 0
0 0 0 0 0 1 0 w6 0
0 0
0 0 1 − 2 1 w7 0
0
Heat Transfer:
The heat transfer (conduction) of a one-dimensional rod shown in Figure 1.4 can
d 2T
be expressed as the differential equation − k =q.
dx 2
The temperature solution of the bar can be searched by the Finite Difference
method at the nodal points in Figure 1.5.
In this case, the unknown temperature values of the bar can be expressed in
matrix form as a system of linear equations as follows
− 2 1 0 0 T1 − Ta
1 −2 1
0 T2 0
=
0 1 − 2 1 T3 0
0 0 1 − 2 T4 − Tb
The above examples can be easily replicated for other fields of engineering.
Systems of linear equations are of great importance in engineering, since problems
that are difficult or difficult to solve analytically are solved by transforming them
into linear or nonlinear equation systems. The solution efficiency and effectiveness
of the linear equation system determines the solution efficiency and effectiveness
of the engineering problem.
2 x1 + 3x2 = 4 , x1 − x2 = 1
Figure 1.6: Graphical solution of a system of linear equations with two unknowns.
It is seen from Figure 1.6 that the solution of the equation with two unknowns is
7 2
around x1 = = 1.4, x2 = = 0.4 . In this method, since it is not possible to draw the
5 5
graph of more than three systems of equations and show the intersection point
graphically, the graphical method cannot be used for solving larger systems of
equations.
a11 x1 + a12 x 2 + a13 x3 + ... + a1n x n = b1 a11 a12 a13 ... a1n x1 b1
a 21 x1 + a 22 x 2 + a 23 x3 + ... + a 2 n x n = b2 a 21 a 22 a 23 ... a 2 n x 2 b2
a31 x1 + a32 x 2 + a33 x3 + ... + a3n x n = b3 a31 a32 a33 ... a3n x3 = b3 (1.2)
... ... ... ... ... ... ... ...
a n1 x1 + a n 2 x 2 + a n 3 x3 + ... + a nn x n = b a n1 a n 2 a n 3 ... a nn x n bn
A X B
The linear equation system in Equation 1.2 can also be written as AX=B in matrix
form. Here, A is the coefficients matrix, X is the unknowns and B is the known
constants.
Example: A set of linear equations with two unknowns can be written in matrix
form as follows:
2 x1 + x2 = 12 2 1 x1 12
4 x1 − 3x2 = 4
➔ 4 − 3 x = 4
2
A X B
In the linear equation system expressed in matrix form as above, it can be easily
understood whether the equations have a common intersection point (solution) by
calculating the determinant (detA) of the coefficients matrix A. There are 3 cases
for the determinant value of A:
Example: Let, 2 x1 + 3x2 = 4 , 2 x1 + 3x2 = 2 . It can be seen from Figure 1.7 that
the equations do not have a common solution (intersection). The
determinant of the coefficients matrix, for which these equations do not
have a solution, can be calculated and shown as follows.
2 x1 + 3x2 = 4 2 3 x1 4 2 3
➔ 2 3 x = 2 ➔ A= ➔ det A = 0
2 x1 + 3x2 = 2 2 2 3
A X B
Figure 1.7: The case of detA=0 (parallel equations) in the system of linear
equations with two unknowns.
c) detA≅ 0 (determinant is very close to zero) condition:
In this case, some of the equations intersect each other at infinity. The
solution of the equations depends on the sensitivity of the computer to which
the solution is made. While a common intersection point of equations can
be obtained in sensitive computers, some equations may be perceived as
parallel to each other in non-precision computers and a common intersection
point may not be obtained. In other words, it depends on the sensitivity of
the computer whether independent equations as much as the unknown
number of mathematical unknowns will appear. In this case, the coefficients
matrix A is called the ill-conditioned matrix.
Example: We can obtain the solution of a general system of linear equations with
three unknowns, by writing the equations in matrix form, using the Gaussian
elimination method as follows.
To obtain the solution, let's apply the elimination and substitution steps to the
above system of equations, respectively.
a) Elemination Step
In the elimination step, all the column elements below the diagonal in the
coefficients matrix A are set to zero. The diagonal term under which all columns
will be reset is called pivot. A systematic is adopted for the reset process. The
terms under the diagonal in row 1 are reset first. Then the terms under the
diagonal in rows 2 and 3, respectively, are reset. For example, to reset the term
a21
a21 below the pivot a11 in the first (1st) row, it is multiplied by row 1 and
a11
subtracted from row 2. To reset the term a31 under the pivot a11 , it is multiplied by
a31
the 1st row and subtracted from the 3rd row. Considering that a ij denotes the
a11
i -th line and the j -th element, the zeroing of the subdiagonal terms can be written
as follows.
a11 a12 a13
pivot x1 b1
a21 a a a a
a2 j − a1 j → a21 − 21 a11 a22 − 21 a12 a23 − 21 a13 x2 = b2 − 21 b1
a11 a11 a11 a11 x a11
a a a a 3
a3 j − 31 a1 j → a31 − 31 a11 a32 − 31 a12 a33 − 31 a13 b3 − a31 b1
a11 a11 a11 a11 a
11
a11 a12 a13 x1 b1
' '
➔ 0 '
a22 a23 x = b2
2
0 '
a32 '
a33 x3 '
b3
The term under its pivot a22 in row 2 can be reset by applying the elimination
'
process again to the new matrix above. It is subtracted from row 3 by multiplying
'
a32
by row 2 to reset the term a32 under its pivot a22 .
' '
'
a22
a
x1 1
a12 a13 b
11
0 a'
22
'
a23 x2 = b2 '
x3 ' a32 '
pivot
'
a '
a32
'
' '
b − b
a3' j − 32 '
→ 0
a32 − ' a22
a
− 32 a ' 3 a22
' 2
'
a ' '
a33 ' 23
2 j
a22 a22 22
a
Note: During elimination, the pivot may become zero even though it was not
initially zero. If the pivot has changed to zero, divisions by zero (indefiniteness)
will occur during elimination (zero). In order to prevent this, in the column where
the pivot is zero before the reset, the absolute value (maximum coefficient) is
determined from the values below the pivot. Then the rows with the zero pivot and
the maximum value are swapped. Thus, the value of the pivot is made non-zero
and then the elimination (reset) process continues.
After the reset process (elimination step) is finished, a matrix form as below is
obtained. In this new matrix form, all terms below the diagonal of the matrix A
are zero.
The matrix form above corresponds to the elimination of x1 from equation 2 and
x1 and x 2 from equation 3.
b) Substitution Step
If the matrix form in Equation 1.3 is written in plain symbolic form as below, it can
easily be seen that the system of equations corresponds to equations that can be
solved one after the other.
𝑎11 𝑥1 + 𝑎12 𝑥2 + 𝑎13 𝑥3 = 𝑏1
′ ′
𝑎22 𝑥2 + 𝑎23 𝑥3 = 𝑏2′ (𝑥1 eleminated)
′′ ′′
𝑎33 𝑥3 = 𝑏3 (𝑥1 ve x2 eleminated)
Starting from the end in the above equations and substituting the result in the
previous equation, all equations can be solved as follows, respectively.
''
a33 x3 = b3'' (equation with one unknown) ➔ x3
'
a22 x2 + a23
'
x3 = b2' (equation with one unknown after substitution x3 ) ➔ x 2
a11 x1 + a12 x2 + a13 x3 = b1 (equation with one unknown after substitution x 2 and x3 ) ➔
x1
Example 1.1: Obtain the solution of the following system of linear equations using
the Gaussian elimination method?
18 x1 + 4 x2 − 3x3 + 5 x4 = 91
− 2 x1 − 24 x2 + 7 x3 − 3x4 = −79
4 x1 − x2 + 32 x3 + 5 x4 = 55
− 9 x1 − 7 x2 − 3x3 + 40 x4 = 20
The above set of equations can be written in AX=B matrix form as follows.
18 4 − 3 5 x1 91
− 2 − 24 7 − 3 x − 79
2
=
4 − 1 32 5 x3 55
− 9 − 7 − 3 40
x4
20
Elimination step:
By applying line-by-line elimination to matrix A and vector B at the same time,
matrix A can be turned into an upper triangle (only the above-diagonal terms are
nonzero). For this, first the terms under the diagonal (pivot) in the first row in
matrix A can be reset as follows:
18
4 − 3 5 x1 91
pivot
− 2 − 24 7 − 3 x 2 = − 79
x 55 ➔
4 − 1 32 5 3
− 9 − 7 − 3 40 4
x 20
91
18 4 −3 5
−2 −2 −2 −2 x −2
− 2 − 18 − 24 − 4 7 − ( −3) − 3 − 5
1 − 79 − 91
18 18 18 18 x 18
2
4 − 4 18 4
− 1 − 4
4
32 − (−3)
4
5 − 5 x = 55 − 4 91
18 18 18 18 3
18
−9 −9 −9 − 9 4
− 9 −
x
18 − 7 − 4 − 3 − (−3) 40 − 5 −9
18 18 18 18 20 − 18 91
Then the terms under the diagonal (pivot) in the second row in matrix A can be
reset as follows:
18 4 −3 5 x1 91
0 − 23.5556 6.6667 − 2.4444
x 2 − 68.8889
pivot
x = 34.7778 ➔
0 − 1.8889 32.6667 3.8889 3
0 −5 − 4.5
42.5 4
x 65.5
18 4 −3 5
0 − 23.5556 6.6667 − 2.4444
− 1.8889 − 1.8889 − 1.8889
0 − 1.8889 − ( )(−23.5556) 32.6667 − ( )6.6667 3.8889 − ( )(−2.4444).
− 23.5556 − 23.5556 − 23.5556
−5 −5 −5
0 −5−( )(−23.5556) − 4.5 − ( )6.6667 42.5 − ( )(−2.4444)
− 23.5556 − 23.5556 − 23.5556
91
x1 − 68.8889
x
2 − 1.8889
= 34.7778 − ( )(−68.8889)
x3 − 23.5556
x 4 −5
65.5 − ( )(−68.8889)
− 23.5556
Then the terms under the diagonal (pivot) in the third row in matrix A can be reset
as follows:
18 4 −3 5 x1 91
0 − 23.5556 6.6667 − 2.4444
x 2 − 68.8889
0 = ➔
0 32
. 4.0849 x3 40.3019
1321
− 5.9151 43.0189 x 4 80.1226
pivot
0 0
18 4 −3 5 x1
0 − 23.5556 6.6667 − 2.4444
x2
0 0 32.1321 4.0849 x
− 5.9151 − 5.9151 3
0 0 − 5.9151 − ( )32.1321 43.0189 − ( ) 4.0849 x 4
32.1321 32.1321
91
− 68.8889
= 40.3019
80.1226 − ( − 5.9151)40.3019
32.1321
Thus, at the end of the elimination process, the following equations are obtained,
in which matrix A turns into an upper triangle.
18 4 −3 5 x1 91
0 − 23.5556 6.6667 − 2.4444 x − 68.8889
2
=
0 0 32.1321 4.0849 x3 40.3019
0 0 0 43.7708
x4
87.5417
Substitution step:
18 x1 + 4 x2 − 3 x3 + 5 x4 = 91
− 23.5556 x2 + 6.6667 x3 − 2.4444 x4 = −68.8889
32.1321x3 + 4.0849 x4 = 40.3019
43.7708x4 = 87.5417
It can be solved x 3 by substituting the x4 = 2 value obtained from the 4th equation
in the 3rd equation. 4.: 32.1321x3 + 4.0849x4 = 40.3019 ➔ x3 = 1
From the above equation expression, matrix A and vector B can be rewritten as
a11 a12 a13 b1
follows. A = a21 a22
a23 , B = b2
a31 a32 a33 b
3
In the Kramer method, unknowns are calculated by using the determinant ratios
of the A' matrix obtained by replacing the A matrix and the A matrix. The matrix
A' is obtained by replacing the matrix A, and the expression of the matrix A' varies
according to which unknown to be solved. Whichever unknown is to be solved, the
A' matrix is obtained by replacing that column in the A matrix with the B vector.
The relevant unknown is calculated by proportioning the determinants of the
matrix A' and A'. For example, if the solution x1 is sought, A' matrix is obtained by
replacing the 1st column in the A matrix with the B vector. Below, the solution of
the system of equations with 3 unknowns by Kramer's method is expressed in
symbolic form.
' '
A
A
b1 a12 a13 a11 a12 b1
𝐴′
b2 a22 a23 ⏞ a21 a22 b2
|𝑎11 𝑏1 𝑎13 |
b3 a32 a33 𝑎21 𝑏2 𝑎23 a31 a32 b3
|𝑎 𝑏3 𝑎33 |
31
det A' 𝑑𝑒𝑡 𝐴′ det A'
x1 = = , 𝑥2 = =
𝑑𝑒𝑡 𝐴
, x3 = = (1.4)
det A 𝑎11 𝑎12 𝑎13 det A
||𝑎21 𝑎22 𝑎23 ||
a11 a12 a13 a11 a12 a13
𝑎31
⏟ 𝑎32 𝑎33
a21 a22 a23 𝐴 a21 a22 a23
a31 a32 a33 a31 a32 a33
A A
Determinant calculation requires a lot of time for large matrices. Therefore, the
Kramer method is mostly used for solving small systems of equations. Some
engineering software consider systems of equations less than 100,000 (one
hundred thousand) variables as small equation systems.
Example 1.2: Solve the following system of linear equations using Kramer's
method.
9 x1 + 10 x2 + 7 x3 = 5
− x1 + 5 x2 + 6 x3 = 9
2 x2 + 3x3 = 12
For the solution with Kramer's method, let's first write the above set of equations
in matrix form.
9 10 7 x1 5
− 1 5 6 x = 9
2
0 2 3 x3 12
A X B
Using the matrix and vector above, the unknowns from the determinant ratios can
be obtained as follows
5 10 7 9 5 7
9 5 6 −1 9 6
12 2 3 − 474 0 12 3 488
x1 = = = -2.7719 , x2 = = = 2.8538 ,
9 10 7 171 9 10 7 171
−1 5 6 −1 5 6
0 2 3 0 2 3
9 10 5
−1 5 9
0 2 12 43
x3 = = = 0.2515
9 10 7 171
−1 5 6
0 2 3
L and U The elements of the matrix can be found by being equal to the left and
right sides of the matrix product as follows:
1.row:
2.row:
a21 = L 21 ➔ L 21 found.
3.row:
a31 = L 31 ➔ L31 found.
a11 a12 0 1 0 0 f1 g1 0
a
21 a22 a23 = e2 1 0 0 f 2 g 2 (1.6)
0 a32 a33 0 e3 1 0 0 f 3
A L U
Again, by using the equality of the left and right sides in matrix multiplication, the
elements of the L and U matrix are obtained as follows.
1.row: a11 = f1 f1
a12 = g1 g1
a21 = e2 f1 e2
2.row:
a22 = e2 g1 + f 2 f 2
a23 = g 2 g 2
a32 = e3 f 2 e3
3.row:
a33 = e3 g 2 + f 3 f 3
After obtaining the special L and U matrices, the system of linear equations will
again be solved one after the other and converted into systems of equations and
solved. From the equation, the temporary unknowns are obtained as follows:
1 0 0 y1 b1 y1 = b1 y1
e
2 1 0 y2 = b2 ➔ e2 y1 + y 2 = b2 y 2
0 e3 1
y3 b3 e3 y 2 + y 3 = b3 y 3
f1 g1 0 x1 y1 f1 x1 + g1 x 2 = y1 x1
0 f g x = y f 2 x 2 + g 2 x3 = y 2 x 2
2 2 2 2 ➔
0 0 f 3 x3 y3 f 3 x3 = y 3 x3
U X Y
L11 0 0 L11 L 21 L 31
A = LL = L 21
T
L 22 0 0 L 22 L 32 (1.7)
L 31 L 32 L 33 0 0 L 33
This decomposition method is also called the Cholesky Decomposition method. For
the Cholesky decomposition to be applied, the coefficients matrix A must be
positive definite. Whether [A] is positive definite can be understood in two ways.
i) For [A] to be positive definite, the absolute value of the element on the
diagonal in any row must be greater than the sum of the absolute values
of the other elements on that row. This can be written mathematically
as:
n
aii aij ( i = 1,..., n )
j =1
j n
Figure 1.8: Example of the case where only B changes in the AX=B linear equation
set.
Example 1.3: Find the solution of the following system of linear equations using
the Cholesky Decomposition method?
18 x1 + 4 x2 − 3x3 + 5 x4 = 91
− 2 x1 − 24 x2 + 7 x3 − 3x4 = −79
4 x1 − x2 + 32 x3 + 5 x4 = 55
− 9 x1 − 7 x2 − 3x3 + 40 x4 = 20
The above set of linear equations can be written in matrix form AX=B as follows
18 4 − 3 5 x1 91
− 2 − 24 7 − 3 x − 79
2
=
4 − 1 32 5 x3 55
− 9 − 7 − 3 40
x4
20
In the Cholesky Decomposition method, matrix A is decomposed as the product of
two special matrices, one in the form of a lower triangle (L matrix) and the other
in the form of an upper triangle (U matrix).
By using the equality of the left and right sides in the matrix multiplication above,
the elements of the matrix can be obtained as follows.
a 31 = L31 ➔ L31 = 4
a32 = L31U12 + L32 ➔ − 1 = 4(0.2222) + L32 ➔ L32 = −1.8889
a33 = L31U13 + L32U 23 + L33 ➔ 32 = 4(−0.1667) + (−1.8889)(−0.2830) + L33 ➔ L33 = 32.1321
a34 = L31U14 + L32U 24 + L33U 34 ➔ 5 = 4(0.2778) + (−1.8889)(0.1038) + 32.1321U 34 ➔
U 34 = 0.1271
Using the 4tt row elements of matrix A:
a41 = L41 ➔ L41 = −9
a42 = L41U12 + L42 ➔ − 7 = −9(0.2222) + L42 ➔ L42 = −5
a43 = L41U13 + L42U 23 + L43 ➔ − 3 = −9(−0.1667) + (−5.0002)(−0.2830) + L43 ➔
L43 = −5.9151
a44 = L41U14 + L42U 24 + L43U 34 + L44 ➔
40 = −9(0.2778) + (−5.0002)(0.1038) + (−5.9151)(0.1271) + L44 ➔ L44 = 43.7708
From the solution LY=B, the temporary unknowns (Y) are obtained as follows
18 0 0 0 y1 91
− 2 − 23.5556
0 0 y 2
− 79 ➔
=
4 − 1.8889 32.1321 0 y 3 55
− 9 −5 − 5.9151 43.7708
y4
20
18 y1 = 91 ➔ y1 = 5.0556
− 2 y1 + (−23.5556) y2 = −79 ➔ y2 = 2.9245
4 y1 + (−1.8889) y2 + 32.1321y3 = 55 ➔ y 3 = 1.2543
− 9 y1 + (−5) y2 − 5.9151y3 + 43.7708 y4 = 20 ➔ y 4 = 2
From the UX=Y solution, the main unknowns (X) are obtained as follows
x4 = 2
x3 + (0.1271) x4 = 1.2543 ➔ x3 = 1
x2 + (−0.2830) x3 + (0.1038) x4 = 2.9245 ➔ x2 = 3
x1 + 0.2222x2 + (−0.1667) x3 + (0.2778) x4 = 5.0556 ➔ x1 = 4
1.4.4 Matrix Inverse Method
In this method, the solution of the system of equations is obtained by multiplying
the inverse of the matrix A with the vector B as follows.
AX = B X = A B
−1
(1.8)
Although the method is simple, the solution time can be large depending on the
dimensions of A. In short, how quickly and easily the inverse ( A
−1
) of A can be
calculated determines the difficulty and time of the solution. Calculating the
inverse of large matrices is often time consuming. Adjoint (Additional matrix),
Jacobi and LU decomposition methods are widely used to calculate the inverse of
matrices.
The adjoint adjA of matrix A can be obtained by transposing the cofactor matrix (
C matrix) corresponding to matrix A. The elements of the C cofactor matrix are
obtained by using the determinants of the sub-matrices to be formed from matrix
A ( adj( A) = C T ). For example, it is calculated as the cofactor term cij = ( −1) i + j Ar
corresponding to the a ij element in the matrix A . Here, Ar the sub (reduced) matrix
represents the matrix obtained by deleting the i -th row and j -th column
elements from matrix A.
Example 1.4: Find the inverse of the following matrix using the Adjoint method?
4 2 1
A = 3 6 2
1 4 8
40 − 22 40 − 12 − 2
T
6
adj ( A) = C T = − 12 31 − 14 = − 22 31 − 5
− 2 − 5 18 6 − 14 18
adj ( A)
In this case, A is the inverse of the matrix. A −1 = It can be obtained as
A
follows, with the expression.
40 − 12 − 2 40 − 12 − 2
− 22 31 − 5 − 22 31 − 5
0.3279 - 0.0984 - 0.0164
adj ( A) 6 − 14 18 6 − 14 18
A −1 = = = = - 0.1803 0.2541 - 0.0410
A 4 2 1 122
0.0492 - 0.1148 0.1475
3 6 2
1 4 8
Example 1.5: Find the inverse of the following matrix using the Gauss-Jordan
elimination method.
4 2 1
A = 3 6 2
1 4 8
With the Gauss-Jordan elimination method, the inverse of the A matrix can be
obtained as follows.
4 2 11 0 0 1 0 0 0.3279 - 0.0984 - 0.0164
3 6 2 0 1 0 0 1 0 − 0.1803 0.2541 − 0.0410
1 4 80 0 1 0 0 1 0.0492 − 0.1148 0.1475
A I I A −1
Note: Like the decomposition method, the inverse of the matrix method is also
effective in solving the problems where the matrix A is the same pattern and the
vector B changes. In such problems, even if the B vector changes, it is sufficient
to calculate the inverse of the A matrix once.
i) LU Decomposition Method:
This method is based on the idea that the product of a matrix A and its inverse is
equal to the unit matrix ( AA −1 = I ). The method can be described using the 3x3
matrix A below.
a11 a12 a13
A = a21 a22 a23
a31 a32 a33
Let's express the inverse of the above matrix A as follows.
By taking one column at a time from the matrix multiplication above, 3 different
linear equation systems can be obtained, which can be solved by the LU
decomposition method as follows.
The inverse of the matrix A can be obtained by solving the above 3 linear system
of equations by LU decomposition method. Returns the elements in the 1st column
of the matrix A−1 which is the inverse of the solution of the 1st system of linear
equations, the elements in the 2nd column of the 2nd column of the solution of
the 2nd linear equation system A−1 , and the 3rd column of the 3rd column of the
solution A−1 of the 3rd linear equation system.
Note: As can be seen from the above, in order to calculate the inverse of a matrix
A of size nxn , it is necessary to solve a system of n linear equations (each
system of equations consists of n unknowns). This explains why calculating the
inverse of large matrices requires a long time and computational cost.
Example 1.6: Find the solution of the following system of linear equations using
the Inverse of the Matrix method?
18 x1 + 4 x2 − 3x3 + 5 x4 = 91
− 2 x1 − 24 x2 + 7 x3 − 3x4 = −79
4 x1 − x2 + 32 x3 + 5 x4 = 55
− 9 x1 − 7 x2 − 3x3 + 40 x4 = 20
With the inverse of the matrix method, the solution of the system of linear
equations in the form of AX=B is expressed as 𝑋 = 𝐴−1 𝐵 as the product of the
inverse of the matrix A (𝐴−1 ) and the vector B.
adj ( A) C T
A −1 = = .
A A
−24 7 −3
𝑐11 = (−1)1+1 | −1 32 5 | = −24(32𝑥40 + 15) − 7(−40 + 35) − 3(3 + 32𝑥7)
−7 −3 40
= −31726
−2 7 −3
( )1+2
𝑐12 = −1 |4 32 5 | = −(−2(32𝑥40 + 15) − 7(160 + 45) − 3(−12 + 32𝑥9))
−9 −3 40
= 4853
−2 −24 −3
( )1+3
𝑐13 = −1 |4 −1 5 | = (−2(−40 + 35) + 24(160 + 45) − 3(−28 − 9))
−9 −7 40
= 5041
−2 −24 7
𝑐14 = (−1)1+4 | 4 −1 32 | = −(−2(−3 + 32𝑥7) + 24(−12 + 32𝑥9) + 7(−28 − 9))
−9 −7 −3
= −5911
4 −3 5
𝑐21 = (−1)2+1 |−1 32 5 | = −(4(32𝑥40 + 15) + 3(−40 + 35) + 5(3 + 32𝑥7))
−7 −3 40
= −6300
18 −3 5
𝑐22 = (−1)2+2 |−1 32 5 | = (18(32𝑥40 + 15) + 3(160 + 45) + 5(−12 + 32𝑥9))
−9 −3 40
= 25305
18 4 5
𝑐23 = (−1)2+3 | 4 −1 5 | = −(18(−40 + 35) − 4(160 + 45) + 5(−28 + 9))
−9 −7 40
= 1095
18 4 −3
𝑐24 = (−1)2+4 | 4 −1 32 | = (18(3 + 32𝑥7) − 4(−12 + 32𝑥9) − 3(−28 + 9))
−9 −7 −3
= 3093
4 −3 5
𝑐31 = (−1)3+1 |−24 7 −3| = (4(280 − 9) + 3(−24𝑥40 − 21) + 5(72 + 49))
−7 −3 40
= −1254
18 −3 5 18 4 5
𝑐32 = (−1)3+2 |−2 7 −3| = −4902, 𝑐33 = (−1)3+3 |−2 −24 −3| = −18240
−9 −3 40 −9 −7 40
18 4 −3
𝑐34 = (−1)3+4 |−2 −24 7 | = −2508
−9 −7 −3
4 −3 5 18 −3 5
𝑐41 = (−1)4+1 |−24 7 −3| = 3650, 𝑐42 = (−1)4+2 |−2 7 −3| = 1904
−1 32 5 4 32 5
18 4 5 18 4 −3
𝑐43 = (−1)4+3 |−2 −24 −3| = 1732, 𝑐44 = (−1)4+4 |−2 −24 7 | = −13624
4 −1 5 4 −1 32
In this case, the Adjoint matrix adj(A) and the inverse of A can be calculated as
follows
−31726 −6300 −1254 3650
4853 25305 −4902 1904
adj(A)=𝐶 𝑇 = [ ]➔
5041 1095 −18240 1732
−5911 3093 −2508 −13624
After calculating the inverse of A, the solution of the set of linear equations is
obtained as follows.
0.0532 0.0106 0.0021 −0.0061 91
−1 −0.0081 −0.0424 0.0082 −0.0032 −79
𝑋=𝐴 𝐵 ➔ 𝑋=[ ]{ }➔
−0.0085 −0.0018 0.0306 −0.0029 55
0.0099 −0.0052 0.0042 0.0228 20
𝑥1 = 4 , 𝑥2 = 3, 𝑥3 = 1, 𝑥4 = 2
1.5 İTERATİVE METHODS
In iterative methods, solution equations are obtained by leaving an unknown from
each equation in the equation system. The solution equations are solved iteratively
and the real solution is tried to be obtained. In iterative methods, the solution
cannot start by itself. Therefore, the initial values are used in the first iteration.
Iterative methods do not guarantee a solution. Whether the solution can be
obtained or not depends on the iterative method, the structure of the system of
equations (the dominance of diagonal values over other values), and the chosen
initial values. Iterative methods are generally more efficient than direct methods
and are therefore preferred for solving large sets of equations. Some commonly
used iterative methods are described in detail below.
Before starting the solution with the Jacobi method, the estimated solution (initial
values) is chosen as x1 , x2 , x3 . By replacing the initial values on the right side
(0)
(0) (0)
of the equations, corrected or renewed solution values are obtained on the left
side. By creating a loop in this way, this loop is continued until the unknown
variable values change slightly. The steps of this cycle are called iterations. Below
is a symbolic explanation of how the unknowns are calculated in the iterations in
the loop.
İteration 1:
İteration k:
If the change in the last two iterations is small enough (eg =0.001), the loop is
stopped and the values in the last iteration are considered the solution to the
system of equations. The Jacobi method has no guarantee of a solution. For a
solution to exist, the terms on the diagonal must be more dominant (greater than
the sum) of the sum of the other terms in that row.
2 x2 + 3x3 = 12 0 2 3
− x1 + 5 x2 + 6 x3 = 9 ➔ A = − 1 5 6
9 x1 + 10 x2 + 7 x3 = 5 9 10 7
The above system of equations cannot be solved by the Jacobi method since the
in coefficient x1 in the first equation is 0. However, if the position of the equations
is changed and the number 0 is prevented from appearing on the diagonal, the
system of equations can be made solvable by the Jacobi method.
After pivoting:
9 x1 + 10 x2 + 7 x3 = 5 9 10 7
− x1 + 5 x2 + 6 x3 = 9 ➔ A = − 1 5 6
2 x2 + 3x3 = 12 0 2 3
In the iterative solution with Gauss-Siedel, the stopping criterion is the same as in
the Jacobi method.
Since the Gauss-Siedel method uses the newest values of the variables in each
iteration, it converges faster than the Jacobi method. Therefore, it is more efficient
than the Jacobi method. The convergence condition in the Gaus-Siedel method is
the same as in the Jacobi method. For convergence, the diagonal terms must be
greater than the sum of the other terms in that row.
n
( aii a
j =1
ij , i = 1,..., n ).
j i
Example 1.7: Find the solution of the following system of linear equations using
the Gauss-Seidel Method?
18 x1 + 4 x2 − 3x3 + 5 x4 = 91
− 2 x1 − 24 x2 + 7 x3 − 3x4 = −79
4 x1 − x2 + 32 x3 + 5 x4 = 55
− 9 x1 − 7 x2 − 3x3 + 40 x4 = 20
It can be shown as follows that the above system of equations satisfies the
convergence condition in the Gauss-Siedel method and therefore can be solved by
the Gauss-Siedel method.
If 𝑥10 = 0, 𝑥20 = 0, 𝑥30 = 0, 𝑥40 = 0 is selected as initial values, the iterative solution is
obtained as follows.
İteration 1:
b1 − (a12 x 2( 0) + a13 x3( 0) + a14 x 4( 0) ) 91
x1(1) = = = 5.0556
a11 18
b2 − (a 21 x1(1) + a 23 x3( 0) + a 24 x 4( 0) ) - 79 - (-2)5.0556
x 2(1) = = = 2.8704
a 22 - 24
b3 − (a31 x1(1) + a32 x 2(1) + a34 x3( 0) ) 55 - 4(5.0556) + (-1)2.8704
x3(1) = = = 1.1765
a33 32
b4 − (a 41 x1(1) + a 42 x 2(1) + a 43 x3(1) ) 20 - (-9)5.0556 + (-7)2.8704 + (-3)1.1765
x 4(1) = = = 2.2281
a 44 40
İteration 2:
b1 − (a12 x 2(1) + a13 x3(1) + a14 x 4(1) ) 91 − 4(2.2281) + (-3)1.1765 + 5(2.2281)
x1( 2) = = = 3.9949
a11 18
b2 − (a 21 x1( 2) + a 23 x3(1) + a 24 x 4(1) ) - 79 - (-2)3.9949 + 7(1.1765) + (-3)2.2281
x 2( 2) = = = 3.0234
a 22 - 24
b3 − (a31 x1( 2) + a32 x 2( 2) + a34 x3(1) ) 55 - 4(3.9949) + (-1)3.0234 + 5(2.2281)
x3( 2) = = = 0.9657
a33 32
b4 − (a 41 x1( 2) + a 42 x 2( 2) + a 43 x3( 2) ) 20 - (-9)3.9949 + (-7)3.0234 + (-3)0.9657
x 4( 2) = = = 2.0004
a 44 40
Similarly, iterations are continued until the values in successive iterations are very
close to each other. After the fourth iteration, the convergence (Convergence
tolerance: = 0.005 ) condition is satisfied and the following solution values are
obtained.
𝑥14 = 4.0033, 𝑥24 = 3.0005, 𝑥34 = 1.0002, 𝑥44 = 2.0009
1.5.3 Optimization Method
Optimization methods are iterative methods that solve minimum (smallest) or
maximum (largest) type problems. If the system of linear equations is transformed
into an optimization problem, it can be solved using optimization methods. For
this, all equations in the linear equation system are written as equal to zero and
then the expressions to the left of the equation are represented by functions such
as f1 , f 2 ,…, f n
k k k
F F F
xk +1
= x −
k
, x2k +1 = x2k − , x3k +1 = x3k − (1.14)
x1 x2 x3
1 1
It shows the number of iterations k and the step length parameter above.
Parameter is usually determined from the solution of a second optimization
problem. In another approach that does not use optimization, either a value is
given in the same iteration and it is checked whether the function value
k +1
decreases ( f ( x ) f ( x k ) ) at the new point ( xik +1 ). If the function value at the
new point is smaller, this point is accepted as the optimum point for this iteration.
If not, the value of the function at the new point is recalculated by reducing its
value (for example, by dividing it in half) and compared with the previous iteration
value. Its value continues to be decreased until the function value at the new point
is less than the function value at the old point.
After the equations are written as equal to zero, the non-zero side f1 ( x1 , x2 ) is
renamed as f 2 ( x1 , x2 ) and
2 x1 + 3x2 − 4 = 0 f1 ( x1 , x 2 ) = 2 x1 + 3x 2 − 4
➔
− x1 + x2 − 9 = 0 f 2 ( x1 , x 2 ) = − x1 + x 2 − 9
F = f1 ( x1 , x2 ) 2 + f 2 ( x1 , x2 ) 2 = (2 x1 + 3x2 − 4) 2 + (− x1 + x2 − 9) 2 ➔ min
SUMMARY
- Numerical solutions of engineering problems are usually expressed directly
or indirectly with linear equations.
- Linear sets of equations can be expressed in matrix form AX=B.
- In order to solve linear equations, independent equations are required as
much as the number of unknowns. Whether this condition is met or not can
be checked by calculating the determinant of the matrix obtained from the
coefficients of the linear equations. The solution should be detA≠0
- Methods for solving linear equations are divided into two groups as Direct
and Iterative methods.
- Direct methods (such as Gauss-Elimination, Decomposition, Inverse of
Matrix, Kramer) and detA≠0 are methods that definitely find the solution.
- Since the number of operations is high in direct methods, they are generally
preferred in solving small equation sets.
- Iterative methods (such as Jacobi, Gauss-Seidel, Optimization methods) are
the methods that find the solution step by step (iteratively) starting from an
initial value (solution estimation).
- Iterative methods do not always find the solution. Finding the solution is
conditional. For the solution, the diagonal terms of the coefficients matrix A
should be dominant compared to the other terms.
- Iterative methods can find the solution faster than direct methods if a good
starting value is chosen.
- Iterative methods are generally preferred for solving large sets of equations.
MATLAB PROGRAMS
Gauss Eliminasyon
function LinearEquation_Solution_GaussElimination
A=[18 4 -3 5 ;
-2 -24 7 -3 ;
4 -1 32 5 ;
-9 -7 -3 40 ] ;
B=[91 ; -79 ; 55 ; 20 ] ;
n=length(B) ;
% 1- ELIMINATION STEP
for ii=1:n-1
for i=ii+1:n
PivotCoeff=(A(i,ii)/A(ii,ii)) ;
for j=ii:n
A(i,j)=A(i,j)-PivotCoeff*A(ii,j) ;
end
B(i)=B(i)-PivotCoeff*B(ii) ;
end
end
% 2- SUBSTITUTION STEP
X=zeros(n,1) ;
for i=n:-1:1
sum=0 ;
for j=1:n
if j~=i
sum=sum+A(i,j)*X(j) ;
end
end
X(i)=(B(i)-sum)/A(i,i) ;
end
A
B
X
LU Decomposition
function LinearEquation_Solution_LU_Decomposition
A=[18 4 -3 5 ;
-2 -24 7 -3 ;
4 -1 32 5 ;
-9 -7 -3 40 ] ;
B=[91 ; -79 ; 55 ; 20 ] ;
n=length(B) ;
L=zeros(n,n) ;
U=zeros(n,n) ;
for i=1:n
U(i,i)=1 ;
end
% A=L*U Decomposition
for i=1:n
for j=1:n
if j<=i
sum=0 ;
for k=1:j-1
sum=sum+L(i,k)*U(k,j) ;
end
L(i,j)=A(i,j)-sum ;
else
sum=0 ;
for l=1:i-1
sum=sum+L(i,l)*U(l,j) ;
end
U(i,j)=(A(i,j)-sum)/L(i,i) ;
end
end
end
% L*Y=B Solution
Y=zeros(n,1) ;
for i=1:n
sum=0 ;
for j=1:n
if j~=i
sum=sum+L(i,j)*Y(j) ;
end
end
Y(i)=(B(i)-sum)/L(i,i) ;
end
% U*X=Y Solution
X=zeros(n,1) ;
for i=n:-1:1
sum=0 ;
for j=1:n
if j~=i
sum=sum+U(i,j)*X(j) ;
end
end
X(i)=Y(i)-sum ;
end
Y
X
Gauss Siedel
function LinearEquation_Solution_Gauss_Siedel
A=[18 4 -3 5 ;
-2 -24 7 -3 ;
4 -1 32 5 ;
-9 -7 -3 40 ] ;
B=[91 ; -79 ; 55 ; 20 ] ;
n=length(B) ;
ConvTol=0.005 ;
MaxIter=1000 ;
% Initial Values
X=zeros(n,1) ;
Conv=1e10 ;
it=0 ;
X0=X ;
for i=1:n
sum=0 ;
for j=1:n
if j~=i
sum=sum+A(i,j)*X(j) ;
end
end
X(i)=(B(i)-sum)/A(i,i) ;
end
% Convergence Check
for i=1:n
if abs(X0(i))<=1e-10
ConvVec(i)=abs(X(i)-X0(i)) ;
else
ConvVec(i)=abs((X(i)-X0(i))/X0(i)) ;
end
end
Conv=max(ConvVec) ;
X0=X ;
end
it
X