Solution of Linear System of Equations
Solution of Linear System of Equations
2
Mathematical Background
• [A] is the shorthand notation for matrix and aij
designates the element at i’th row and j’th column column 1
of this matrix.
a11 a12 ... a1m
• A matrix with n rows and m columns is referred to a a
row 2
as an “n by m matrix”. ... a2m
A 21 22
• Matrices with n=1 rows are called row vectors:
• an1 an2 ... anm
3
Mathematical Background, cont.
• For vectors, one subscript is sufficient. For matrices, we need two subscripts.
• Matrices where n=m are called square matrices.
• The diagonal consisting of elements aii (a11, a22,…, ann) of the square matrix [A] is
termed the main diagonal.
• A square matrix with aij= aji is called a symmetric matrix.
5 0 −1
1 2
• 𝐴 = 0 2 4 , 𝐵 =
2 0
−1 4 7
• A square matrix with all elements off the main diagonal equal to zero is called a
diagonal matrix.
𝑎 0
𝑎
• 𝐴 = , aij=0 if i≠j for i,j=1,2,…,n
⋱
0 𝑎 4
Mathematical Background, cont.
• The diagonal matrix with all elements on the main diagonal equal to
1 is called the identity matrix:
• The matrix with all elements below the main diagonal equal to zero
is called an upper triangular matrix:
5
Mathematical Background, cont.
• The matrix with all elements above the main diagonal equal to zero
is called a lower triangular matrix:
• Solution
•
7
Mathematical Background, cont.
• Matrix division is not a valid matrix operation, therefore a
matrix cannot be divided by another. If a matrix [A] is square
and nonsingular the inverse of [A] is defined as:
•
• Thus, multiplication of a matrix by the inverse of another is
analogous to division.
• The inverse of a two dimensional matrix can be obtained as:
•
• The transpose of a matrix is defined as:
• ,
• (Therefore the transpose of a symmetrical matrix is the matrix itself.)
8
Mathematical Background, cont.
• A column vector can be converted to a row vector by the
transpose operation:
9
Mathematical Background, cont.
• System of linear algebraic equations can be represented in
matrix form:
• , or,
10
Mathematical Background, cont.
• Solution of this equation system can be obtained after
calculating the inverse of [A], as follows:
•
•
•
• Therefore, the equation system is solved and the unknowns/variables
are obtained.
11
Non-Computer Methods For the Solution of
Linear System of Equations
• For small linear equation systems (n≤3) we can use the graphical
method, Cramer’s rule and the elimination of unknowns.
• The Graphical Method
• Let’s consider a system of equations with n=2.
•
• Solution
•
a11 a12 a13
• the determinant of [A] is shown as: A a21 a22 a23
a31 a32 a33
• Determinant is a scalar quantity. For a n=2 matrix it can be calculated
as:
a11 a12
A a11a22 a12a21
a21 a22
16
Non-Computer Methods For the Solution of
Linear System of Equations, cont.
• For a n=3 matrix, the determinant can be calculated as:
a11 a12 a13
a a23 a a23 a a22
A a21 a22 a23 a11 22 a12 21 a13 21
a32 a33 a31 a33 a31 a32
a31 a32 a33
a11 a22a33 a23a32 a12 a21a33 a23a31 a13 a21a32 a22a31
1
x1 x2 1
2 1 / 2 1 1 1
D 0
1 1 1 / 2 1 2 2
x1 x2
2 2
18
Example 9.2, cont.
1
x1 x2 1 1 / 2 1 1
2 D 2 1 0
1 2 2
x1 2 x2 2
2.3
x1 x2 1.1
5 2.3 / 5 1 2.3 1
1
D 0.04
x1 x2 1 1 / 2 1 5 2
2
19
Non-Computer Methods For the Solution of
Linear System of Equations, cont.
• Singular systems have coefficient matrix with its determinant equal to zero.
• The ill-conditioned systems have determinants close to zero (when scaled).
• Cramer’s Rule
• We can solve the following 3x3 equation system
𝑎 𝑎 𝑎 𝑥 𝑏
• 𝑎 𝑎 𝑎 𝑥 = 𝑏 , 𝐴 𝑋 = 𝐵
𝑎 𝑎 𝑎 𝑥 𝑏
• as follows:
b1 a12 a13 a11 b1 a13 a11 a12 b1
b2 a22 a23 a21 b2 a23 a21 a22 b2
b a a a b a a a b3
x1 3 32 33 , x2 31 3 33 and x3 31 32
A A A
20
Example 9.3
• Use Cramer’s rule to solve
0.01 0.52 1
0.67 1 1.9
• 0.44 0.3 0.5 0.03278
x1 14.9
0.0022 0.0022
0.3 0.01 1
• Solution 0.5 0.67 1.9
0.1 0.44 0.5 0.0649
• x2 29.5
0.0022 0.0022
0.3 0.52 1 and
1 1.9 0.5 1.9 0.5 1
A 0.5 1 1.9 0.3 0.52 1 0.0022 0.3 0.52 0.01
0.3 0.5 0.1 0.5 0.1 0.3
0.1 0.3 0.5 0.5 1 0.67
(This method is impractical for large system of equations (n>3) 0.1 0.3 0.44 0.04356
x3 19.8
since the calculation of determinants is time consuming.) 0.0022 0.0022 21
Non-Computer Methods For the Solution of
Linear System of Equations, cont.
• The Elimination of Unknowns
• Let’s consider the equation system:
•
• The basic strategy of this method is to multiply the equations by
constants so that one of the unknowns will be eliminated when
equations are combined.
• For example, multiply first equation by a21 and the second equation
by a11:
•
• Subtracting one from the other we have:
•
22
Non-Computer Methods For the Solution of
Linear System of Equations, cont.
• This result can be substituted to any of the two equations to
obtain:
•
23
Example 9.4
• Sum equations:
• Solve •
•
• Use the first equation to solve
• By using the elimination of for x1:
unknowns. •
• Solution
• Multiply second equation by 3:
•
24
Computer Methods
Naive Gauss Elimination
• The method is used to solve the linear system of algebraic
equations:
• or x2 a23
a22 x3 ... a2 n xn b2
a11 x1 a12 x2 a13 x3 ... a1n xn b1
x2 a23
a22 x3 ... a2 n xn b2
• The procedure is repeated by multiplying first equation with
(a /a ) then subtracting from the third equation. x2 a33
a32 x3 ... a3 n xn b3
31 11
• Repeating the same procedure for all equations: .
.
.
an 2 x2 an 3 x3 ... ann
xn bn 26
Naive Gauss Elimination,
Forward elimination of unknowns, cont.
27
Naive Gauss Elimination,
Forward elimination of unknowns, cont.
a11 x1 a12 x2 a13 x3 ... a1n xn b1
• When we continue with the
remaining pivoting equations, we x2 a23
a22 x3 ... a2 n xn b2
have: x3 ... a3n xn b3
a33
• Now the system has been .
transformed to upper triangular .
form.
.
xn bn
n 1 n 1
ann
28
Naive Gauss Elimination,
Back substitution
• The last one of these equations can be solved to give:
•
( )
• )( ( ) ,
)(
• , for i=n,n-1,…,1
29
Naive Gauss Elimination,
Back substitution
• The method is called “naive” since it does not account for the
possibility that the pivoting terms in the forward elimination
phase might be equal to zero (the division by pivoting elements
that are equal to zero will give division by zero error during the
forward elimination!).
30
Example 9.5
• Use Gauss elimination to solve third equation:
3𝑥 − 0.1𝑥 − 0.2𝑥 = 7.85
• 0.1𝑥 + 7𝑥 − 0.3𝑥 = −19.3 3𝑥 − 0.1𝑥 − 0.2𝑥 = 7.85
• 7.00333𝑥 − 0.293333𝑥 = −19.5617
0.3𝑥 − 0.2𝑥 + 10𝑥 = 71.4 10.0120𝑥 = 70.0843
• Round-off errors: A lot of arithmetic operations are carried out and we can have
large magnitude of round-off errors. To avoid these errors we can use more
significant figures in calculations by hand. In computer programs, we can use
double precision variables.
• Solution
• The scaling of first system of equations gives:
• , (indication of well condition)
38
Example 9.9
• Use the “naive” Gauss elimination to solve • −9999𝑥 = −6666 → 𝑥 =
0.0003𝑥 + 3.0000𝑥 = 2.0001
• • Substituting this result in the first equation
1.0000𝑥 + 1.0000𝑥 = 1.0000
and solving for x1, we have:
• Then, repeat computation with partial
pivoting • 𝑥 =
.
.
• Solution • Using 3 significant figures in computation:
• The system is not ill-conditioned, after • 𝑥 = 0.667, 𝑥 =
. .
= −3
scaling we have: .
• Using 4 significant figures in computation:
. .
0.0001𝑥 + 1.0000𝑥 = 0.6667 • 𝑥 = 0.6667, 𝑥 = =0
• .
1.0000𝑥 + 1.0000𝑥 = 1.0000
• 𝐷 = 0.0001 × 1 − 1 × 1 = −0.9999
40
Example 3
• Solve the linear algebraic equation system by Gauss elimination with
partial pivoting.
41
Example 3, cont.
Switch 1st and 2nd rows
v (Pivoting)
Forward elimination of x1
Forward elimination of x2
No switching required since
the pivoting term is already largest (in magnitude)
Forward elimination of x3 Back substitution gives:
x1=5.97332, x2=5.09664,
x3=7.03448, x4=3.02997
42
Example 4 (determinant with partial pivoting)
• Calculate the determinant of matrix [A] using Gauss elimination with partial pivoting.
s=1
44
Example 5
• Three masses are suspended k1
m3
x3
45
Example 5, cont.
• Let’s write the force equilibrium for each mass:
𝑘 𝑥 = 𝑚 +𝑚 +𝑚 𝑔 k1
• 𝑘 𝑥 −𝑥 = 𝑚 +𝑚 𝑔
𝑘 𝑥 −𝑥 = 𝑚 𝑔 m1
x1
• In matrix form:
𝑘 0 0 𝑥 𝑚 +𝑚 +𝑚 𝑔 k2
• −𝑘 𝑘 0 𝑥 = 𝑚 +𝑚 𝑔
0 −𝑘 𝑘 𝑥 𝑚 𝑔 m2
x2
• For the given values of parameters, we have:
10 0 0 𝑥 73.575 k3
• −10 10 0 𝑥 = 53.955
0 −10 10 𝑥 24.525
m3
• Using Gauss elimination, we have: x3
• x1=7.3575m, x2=12.753m and x3=15.2055m
46
Gauss-Jordan Method
• This method is a variation of the Gauss elimination method. The
major difference is that when an unknown is eliminated, it is
eliminated from all equations. The method is illustrated in the
following example.
• Example
• Solve the system of linear algebraic equations by using the Gauss-
Jordan method: