Lecture 4
Lecture 4
1
10/04/2021
linear egu→a×+by+c=O " ↳ if
[email protected]
ax+by= - C
In this part we deal with the case of determining the values x1, x2, …, xn that
simultaneously satisfy a set of equations
𝑓 𝑥 ,𝑥 ,…,𝑥 =0
𝑓 𝑥 ,𝑥 ,…,𝑥 =0
.
.
.
𝑓 𝑥 ,𝑥 ,…,𝑥 =0
Where every equation is linear algebraic equation of the general form
𝑎 𝑥 + 𝑎 𝑥 + ⋯+ 𝑎 𝑥 = 𝑏
𝑎 𝑥 + 𝑎 𝑥 + ⋯+ 𝑎 𝑥 = 𝑏
.
.
.
𝑎 𝑥 + 𝑎 𝑥 + ⋯+ 𝑎 𝑥 = 𝑏
Engr310 – Numerical Methods for Engineers Majdi Adel 3
Row vectors Symmetric matrix (aij = aji for all i’s and j’s)
𝐵 = 𝑏 𝑏 ⋯ 𝑏 5 1 2
[ 137 ]
512
𝐴 = 1 3 7 →
Column vectors 2 7 8 278
𝑐
𝑐 Diagonal matrix any no
𝐶 = →
.
⋮ 𝑎 0 0
𝑐 𝐴 = 0 𝑎 0
Square matrix (n = m) 0 0 𝑎
𝑎 𝑎 𝑎 Identity matrix
𝐴 = 𝑎 𝑎 𝑎 1 0 0
𝑎 𝑎 𝑎 𝐼 = 0 1 0
0 0 1
cis 81=6*1,6
Engr310 – Numerical Methods for Engineers Majdi Adel 4
2
10/04/2021
Ef
𝑎 𝑎 𝑎 addition ← j
𝐴 = 𝑎 𝑎 𝐴 + 𝐵 + 𝐶 = 𝐴 + 𝐵 + 𝐶
𝑎 𝑔𝑎 𝑔𝑎 𝑔𝑎
𝑔𝐴 = 𝑔𝑎 𝑔𝑎 𝑔𝑎
Lower triangular matrix
𝑔𝑎 𝑔𝑎 𝑔𝑎
𝑎
JM # ↳ 81W
𝐴 = 𝑎 𝑎 Matrix product j @ is
𝑎 𝑎 𝑎 £94
a
𝐶 = 𝐴 𝐵 𝑐 = 𝑎 𝑏
Banded matrix
𝑎 𝑎 Multiplication of two matrices can be performed only if the
first matrix has as many columns as the number of rows in
𝑎 𝑎 𝑎
𝐴 = 𝑎 𝑎
the second matrix
𝑎
𝐴 × 𝐵 × = 𝐶 ×
𝑎 𝑎
Engr310 – Numerical Methods for Engineers Majdi Adel 5
3
10/04/2021
2𝑥 + 𝑥 + 3𝑥 = 7 3 1 6 𝑥 2
3𝑥 + 𝑥 + 6𝑥 = 2 Vector of constants
Matrix of coefficients si
Mol # f-
*I ID 'd
a. 6- µ ②j ①
It is useful to augment [A] with [B] since I 8>61
some techniques used for solving of linear c. 1 1 1 4
systems perform identical operations on a 2 1 3 7 →
② 215-8 6%
Determinants
and Cramer’s
Rule
Engr310 – Numerical Methods for Engineers Majdi Adel 8
4
Crammer 's Rules from
Math for EE
10/04/2021
Ix pls b
Determinants
'
Determinants can be used to determine if the system has a unique solution or not.
They also can be used to solve the system
For the coefficient matrix [A], if:
0 𝑡ℎ𝑒 𝑠𝑦𝑠𝑡𝑒𝑚 ℎ𝑎𝑠 𝑛𝑜 𝑢𝑛𝑖𝑞𝑢𝑒 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛
÷ -
si am
ii.
𝑑𝑒𝑡 A = 6728
≠ 0 𝑡ℎ𝑒 𝑠𝑦𝑠𝑡𝑒𝑚 ℎ𝑎𝑠 𝑎 𝑢𝑛𝑖𝑞𝑢𝑒 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛
\
We define the determinant of the N x N matrix [A] as:
night
𝑑𝑒𝑡 A = … 𝐸 … 𝑎 , 𝑎 , …𝑎 ,
5
10/04/2021
÷ :] / ¥;] [ § ]
922 923
:
𝑏 𝑎 𝑎 𝑎 𝑏 𝑎 𝑎 𝑎 𝑏
𝑏 𝑎 𝑎 𝑎 𝑏 𝑎 𝑎 𝑎 𝑏
𝑏 𝑎 𝑎 𝑎 𝑏 𝑎 𝑎 𝑎 𝑏
𝑥 = 𝑥 = 𝑥 =
𝐷 𝐷 𝐷
Cramer’s rule gives the exact solution to the system. However, for more than three equations, Cramer’s rule
becomes impractical because calculating the determinants is time consuming even by computers
Example
Use Cramer’s rule to solve the following linear system
𝑥 + 2𝑥 + 3𝑥 = 0
4𝑥 + 5𝑥 + 6𝑥 = 0
7𝑥 + 8𝑥 + 13𝑥 = 1
6
10/04/2021
Since D ≠ 0, the matrix of coefficients is nonsingular and we have a unique solution to the system
Step 3: To calculate x1, replace the first column with the vector of constants and calculate the
determinant
0 2 3 0 6
𝐷 = = 0 13 − 6 1 = −6
𝐷= 0 5 6 1 13
1 8 13 0 5
= 0 𝐷 − 2 𝐷 + 3 𝐷 𝐷 = = 0 8 − 5 1 = −5
1 8
𝐷 = 0 − 2 −6 + 3 −5 = −3
0 2 3
0 5 6
−3
𝑥 = 1 8 13 = = 0.25
𝐷 −12
7
10/04/2021
Step 4: To calculate x2, replace the second column with the vector of constants and calculate the
determinant
1 0 3 0 6
𝐷 = = 0 13 − 6 1 = −6
𝐷= 4 0 6 1 13
7 1 13 4 0
= 1 𝐷 − 0 𝐷 + 3 𝐷 𝐷 = = 4 1 − 0 7 =4
7 1
𝐷 = 1 −6 − 0 + 3 4 = 6
1 0 3
4 0 6
𝑥 = 7 1 13 = 6 = −0.5
𝐷 −12
Step 5: To calculate x3, replace the third column with the vector of constants and calculate the
determinant
1 2 0 5 0
𝐷 = = 5 1 − 0 8 =5
𝐷= 4 5 0 8 1
7 8 1 4 0
= 1 𝐷 − 2 𝐷 + 0 𝐷 𝐷 = = 4 1 − 0 7 =4
7 1
𝐷 = 1 5 − 2 4 + 0 = −3
1 2 0
4 5 0
−3
𝑥 = 7 8 1 = = 0.25
𝐷 −12
8
10/04/2021
Gauss
Elimination
ñ Mdl :b 2
↳
Deism 2
# AH it
matrixg ← &
upper triangular
Is ok
Gauss Elimination ( Row Echelon Form)
This approach can be Forward elimination
Starting with the first row, add or
extended to a large system subtract multiples of that row to
of equations by developing eliminate the first coefficient from the
IMA # second row and beyond
a systematic algorithm to ¥ Continue this process with the second
upper triangular matrix
.
v. wisdom
8 @ b. Ml& Back substitution
Starting with the last row, solve for
if 6
,
@ I Ñ_ the unknown, then substitute that
value into the next highest row
Each row will contain only one more
unknown because it is an upper-
triangular
Engr310 – Numerical Methods for Engineers Majdi Adel 18
9
ibis # iii. µ
,
g. a viper triangular j ! A.
- : J WI I -0 'S
✗ + ✗ - ✗ =
1
, z }
3 ×, + ✗ -1 ✗ = 9
z 3
✗ -
✗ + 4 ✗ =
8
, z 3
.
:
As I & im I aids @I
1 : : :L :|
3 1 I
i.
Math for EE & id "
↳ É if 181 Hibi
[ §O ! ! / § ]
,
Rz =3 Ri
R} =
Rz
-
-
Ra
R, \
31 }
3 3
I
-
I -1 " ?o
1?
::÷
new
Rz
.
%
"
}
[ ! I
0
⑦ 5 µ]
7
R, = Rub
I 5
4
/
0 2 -
::
[ O
! I
o
-
I
I /¥ *
&
← a-
£
µ,
I
_Ñ I
: ✗ = I
}
.
i. 2 ✗z - Y X = 6
}
-
✗
z
=
-61¥ = I
: .
✗ -1 ✗ -
✗ = I
, , }
✗ I 1- ✗ ✗
z
-
=
, }
= I + I -
C 1)- = 3
- 8,41 & it:-& @ a- A bit ↳ SW
" Ñ_ 1014 # b. is Wi:@ µ,
pivoting
element Pivoting egg
④
.
-
,
[f-11
I %' 'd MI%iz↳ , ↳
Caz / an )×R,
. -
µ #
"
d d I am
.
B) %
calm µ,
o.w.ly Pivoting JI &
I. WIKIA them Pivoting
@
.
egu
.
① 3- (3-1.1)×1=0 ② I - (3-1.1)×1=-2
③ I - (3%1)×-1=4 ⑨ 9- (3-11)×1=1
[ 1-148-0
'
I ]
'
11
"
0 -
2 4
ji-WI.be#[email protected]=Rz-(a31/an)XRi-
i.
' "
arm
g ↓ g.
~ #
.
g.
I
Pivoting
→
%
'm & , # dem
WWII ◦
.
pivoting i
µ #
eqa .
① I -
(1%1)×1=0 ② - I -
(1-1.1)×1=-2
③ 4- (1%1)×-1=5 ④ 8- (1%1)×1=7
' ' '
\
'
-
-
elem .
⑦ 0 5 7
i.
gjiog-ww-k.gl 2 -61
.
t.us#-2.gWlk1z.s-tpivotingequ. J.&R;--Rz-(azz
pivoting elem .
)✗R% / 922
'
Ms#
'
'd d ↓
µ ,
I -6
'
% '
µ Pivoting B)
* * 11
.
µ # Pivoting eqa .
① -2 -
C -
2. ÷ -
2) ✗ -2=0 ② 5- C- 2 ÷ -27×4=1
③ 7- ( - 2. ÷ -
2) ✗ 6=1
[
' ' '
f]
-
'
0 -2 4 6 µ? # Ñ_↳
I
O O I
txt £
3=1 ✗
-
2×2+4×3=6 ✗ 2=-1
✗ ✗
2-
✗
(+3=1 → ×
, =3
10/04/2021
Forward Elimination
𝑎 𝑎 … 𝑎 𝑏
𝑎 𝑎 … 𝑎 𝑏 Pivoting equation
⋮ ⋮ ⋱ ⋮ ⋮ Pivoting element
𝑎 𝑎 … 𝑎 𝑏
First elimination step is to eliminate the first
unknown x1, from the second through the nth
equations
𝑎
𝑅𝑎𝑤 = 𝑅𝑎𝑤 − 𝑅𝑎𝑤 𝑎 𝑎 … 𝑎 𝑏
𝑎
𝑎 0 𝑎 … 𝑎 𝑏
𝑅𝑎𝑤 = 𝑅𝑎𝑤 − 𝑅𝑎𝑤 ⋮ ⋮ ⋱ ⋮ ⋮
𝑎
0 𝑎 … 𝑎 𝑏
𝑎
𝑅𝑎𝑤 = 𝑅𝑎𝑤 − 𝑅𝑎𝑤
𝑎
Engr310 – Numerical Methods for Engineers Majdi Adel 19
10
10/04/2021
Back Substitution
𝑎 𝑎 … 𝑎 𝑏
0 𝑎 … 𝑎 𝑏
⋮ ⋮ ⋱ ⋮ ⋮
0 0 … 𝑎 𝑏
Starting from the last raw to solve for xn
𝑏
𝑥 =
𝑎
This result is back-substituted into the (n − l)th equation to solve for xn−1. Repeat
this procedure to evaluate the remaining x’s
𝑏 −∑ 𝑎 𝑥
𝑥 = 𝑓𝑜𝑟 𝑖 = 𝑛 − 1, 𝑛 − 2, ⋯ , 1
𝑎
Example
Solve the following linear system using Gaussian elimination
𝑥 +𝑥 −𝑥 =1
3𝑥 + 𝑥 + 𝑥 = 9
𝑥 − 𝑥 + 4𝑥 = 8
11
10/04/2021
1 −1 1
1
3 1
1 9
1 −1
4 8
3
𝑅𝑎𝑤 = 𝑅𝑎𝑤 − 𝑅𝑎𝑤 1 1 −1 1
1
0 −2 4 6
1
𝑅𝑎𝑤 = 𝑅𝑎𝑤 − 𝑅𝑎𝑤 0 −2 5 7
1
1 1 −1 1
0 −2 4 6
0 0 1 1
1
𝑥 = =1
1
6− 4 1
𝑥 = = −1
−2
1 − 1 −1 − −1 1
𝑥 = =3
1
Always substitute the solution set in the original system to check if it is correct or not
12
first method : -
10/04/2021
[% I -211-4 ]R [⑥ ¥1 ] ⑤ Y Is
-→[
's
1- }
◦ -
_
,
/4 Resp R, -6.5
0.25
-
, 0 -3.25
6 I 1 6 1 I 6
R3=6R ,
-
Rz→ o
④ -2.5 -9
find
[ 25-0-251-0 ]
To
R3=2Rz
◦
'
's ✗ / Xz × :
R} →
'
, ,
}
.
-6.5
-
0 0 25-3-25 ✗ 3=-41
-4=1 0.25×2-3.25×3=-6.5
-
→ ✗ 2=-13
,
O O
-
y -
y
×,
-10.25×2-0.25×3=-0-5 →
✗
1=3
Example
Solve the following linear system using Gaussian elimination
4𝑥 + 𝑥 − 𝑥 = −2
[
" ' "
5𝑥 + 𝑥 + 2𝑥 = 4
6𝑥 + 𝑥 + 𝑥 = 6
5
6
I
I
2
1
Y] 4
6
Second method :
Pivoting dens
-
"°ᵗiⁿdem
pivoting ego
I
.
.
[ ⑤fRi=R
If Ri :P }
,
-
-
Caz ,
Caz /a.) ✗ R
/ an )xR ,
-→[%|¥Piʳtiⁿe9tR}"=Rj
0-o-52.CM
-
( as ,
/
az )xRi ,
, ,
find
[ -11
at % ✗ ✗ 2) ×
I / :
}
.
→ ✗ 3=-41
-0.253.2s -4=1 6.5 ✗ 2=-13
g. 0.25×2+3.25×3 = →
O o -4 4 ✗ it
1×2-1×3=2 →
✗
1=3
Engr310 – Numerical Methods for Engineers Majdi Adel 25
Example
Solve the following linear system using Gaussian elimination
3𝑥 − 0.1𝑥 − 0.2𝑥 = 7.85
0.1𝑥 + 7𝑥 − 0.3𝑥 = −19.3
0.3𝑥 − 0.2𝑥 + 10𝑥 = 71.4
13
10/04/2021
Ñ
.
.
b) I o a elim 1 NG
Pitfalls of Elimination Methods
HI → I 4
Division by Zero →
µ is pivoting y g Round-off Errors
dem .
equations :&
i
, @
'M ÷ ] .
↳ .
C-
-
+
g- 14
10/04/2021
Pivoting
Gauss elimination may result in one or more of the coefficients on the main diagonal
(pivot element) are equal to zero (division by zero) or close to zero (round off errors)
To avoid this problem pivoting is used
Switching the rows so that the largest element is the pivot element
15
10/04/2021
Example
Solve the following linear system using Gaussian elimination
0.0003𝑥 − 3.0000𝑥 = 2.0001
1.0000𝑥 − 1.0000𝑥 = 1.0000
First without pivoting, then by applying partial pivoting. Compare the results with the exact solution
of x1 = 1/3, x2 = 2/3. (use 4 decimal places)
Without pivoting
Step 1: Eliminating x1 from the second row
0%1 DX is ! b) I
0.0003 3.0000 2.0001
1.0000 1.0000 1.0000
1.0000 0.0003 3.0000 2.0001
𝑅𝑎𝑤 = 𝑅𝑎𝑤 − 𝑅𝑎𝑤
0.0003 0.0000 −9999 −6666
16
10/04/2021
With pivoting: Switch the rows to make the pivot element a11 the largest
Step 1: Eliminating x1 from the second row
1.0000 1.0000 1.0000 I :@ go.MX Jw ↳ .
Without pivoting
With pivoting
17
10/04/2021
Scaling
In some cases, the coefficients of some equations in the system have much larger
magnitude than others. Therefore, scaling is used to minimize round-off errors in such
cases
Example
Solve the following linear system using Gaussian elimination
2.000𝑥 + 100000𝑥 = 100000
𝑥 + 𝑥 = 2.000
First without scaling, then by scaling the equations so that the maximum coefficient in each row is 1.
Compare the results with the exact solution of x1 = 1, x2 = 1. (use 3 decimal places)
É 1 ; }
g
you @ #
I
His WII
18
10/04/2021
Without scaling
Step 1: Eliminating x1 from the second row
@ @ & Scatting
jgw.sc
2.000 100000 100000 .
19
10/04/2021
Gauss-Jordan
btw ① gl ,
Gauss -
Jorden
Gauss-Jordan
It is a variation of Gauss elimination. The difference is when an unknown is eliminated
in the Gauss-Jordan method, it is eliminated from all other equations. In addition, all
rows are normalized by dividing them by their pivot elements. Thus, the elimination
step results in an identity matrix rather than a triangular matrix
Wig 1 MI
69@ 111 AH b- % Ij
y @ gl
20
10/04/2021
Example
Solve the following linear system using Gaussian-Jordan elimination
3𝑥 − 0.1𝑥 − 0.2𝑥 = 7.85
0.1𝑥 + 7𝑥 − 0.3𝑥 = −19.3
0.3𝑥 − 0.2𝑥 + 10𝑥 = 71.4
21
10/04/2021
𝑥 = 3.0000
𝑥 = −2.5000
𝑥 = 7.0000
22
10/04/2021
Example
Solve the following linear system using Gaussian-Jordan elimination
𝑥 −𝑥 =2
2𝑥 − 𝑥 − 𝑥 = 3
𝑥 +𝑥 +𝑥 =6
The answer is x1 = 3, x2 = 1, x3 = 2
23