Professional Documents
Culture Documents
Chapter 1-2 Matrix Algebra
Chapter 1-2 Matrix Algebra
(BDA 31003)
Matrix Operations
Addition
Multiplication
Inverse
Orthogonal Matrix
Solution of Simultaneous Equations
2
Matrix Definition
Column n
3
Example Matrix Definition
Rectangular matrix 5 3 −3 2
𝑀 = 2x4
−6 5 4 −19
5 3 −3
Square matrix 𝐶 = 5 4 −19 3x3
2 4 −3
Vector
5 5
Column matrix (Vector) 𝐹 = 3 = 3
3x1
−3 −3
4
Transpose Matrix
5 3 −3 5 5 2
𝐶 𝑇 = 3
𝐶 = 5 4 −19 4 4
−3 −19 −3
2 4 −3
Diagonal
unchanged
5
Transpose Matrix
in OO/LO Calc Spreadsheet
Prepare data
Insert function
TRANSPOSE
Select the array data
Prepare area for result
OK
To show
The result
6
Transpose Matrix
in MS Excel
Prepare data
Insert function
TRANSPOSE PRESS F2
Select the array data
then
8
Symmetric Matrix
𝐶 is a symmetric matrix
9
Unit Matrix
𝑎 𝐼 = 𝐼 𝑎 = 𝑎
The unit matrix is always a square matrix of any possible
order with each element of the main diagonal is one and
all other elements equal to zero.
1 0 0
For example, the 3 x 3 unit matrix
is given by
𝐼 = 0 1 0
0 0 1
10
Addition of Matrices
Matrices of the same order can be added together by
summing corresponding elements of the matrices.
Subtraction is performed in similar manner
Matrices of unlike order cannot be added or subtracted.
−1 2
[𝐴] = 0 4
−3 2 [𝐶] = [𝐴] + [𝐵] =
0 3
1 2
[𝐵] =
3 1
11
Addition of Matrices
in FreeMat / Matlab
12
Multiplication of Matrices
The number of the columns of the first matrix must be
equal to the number of rows of the second matrix.
Matrix multiplication is not cumulative [A][B]≠[B][A]
Prepare data
[A] and [B]
OK
To show
The result
14
Multiplication of Matrices
in FreeMat
15
Inverse of a Matrix
−1
𝐶 𝑇 𝑎𝑑𝑗 𝐴
𝐴 = =
∣𝐴∣ ∣𝐴∣
𝐶 : Cofactor of matrix 𝐴
∣ 𝐴 ∣ : Determinant of matrix 𝐴
16
Cofactor Matrix
−1 3 −2
[𝐴] = 2 −4 2
0 4 1
−4 2 2 2 2 −4
+∣ ∣ −∣ ∣ +∣ ∣
4 1 0 1 0 4 −12 −22 8
3 −2 −1 −2 −1 3
𝐶 = −∣ ∣ +∣ ∣ −∣ ∣ = −11 −1 4
4 1 0 1 0 4
3 −2 −1 −2 −1 3 −2 −2 −2
+∣ ∣ −∣ ∣ +∣ ∣
−4 2 2 2 2 −4
17
Adjoint and Determinant Matrix
−12 −11 −2
𝑇
𝑎𝑑𝑗 𝐴 = 𝐶 = −2 −1 −2
8 4 −2
𝑑𝑒𝑡 𝐴 =∣ 𝐴 ∣
−4 2 2 2 2 −4
= −1 +1 ∣ ∣ + 3 −1 ∣ ∣ − 2 +1 ∣ ∣
4 1 0 1 0 4
= −10
18
Determinant of a Matrix
in OO Calc Spreadsheet
Insert function MDETERM Select the array data [A]
OK
To show
The result
19
Determinant of a Matrix
in FreeMat
20
Inverse of a Matrix
in OO Calc Spreadsheet
OK
To show
The result
21
Inverse of a Matrix
in FreeMat
22
Orthogonal Matrix
A matrix [A] is an orthogonal matrix if
−1 𝑇
𝐴 = 𝐴
24
Linear Equations in Matrix
𝑎11 𝑥1 + 𝑎12 𝑥2 + ⋯ + 𝑎1n 𝑥𝑛 = 𝑐1
𝑎21 𝑥1 + 𝑎22 𝑥2 + ⋯ + 𝑎2n 𝑥𝑛 = 𝑐2
⋮
𝑎𝑛1 𝑥1 + 𝑎𝑛2 𝑥2 + ⋯ + 𝑎𝑛𝑛 𝑥𝑛 = 𝑐𝑛
−1 3 −2 𝑥1 2
2 −4 2 𝑥2 = 1
0 4 1 𝑥3 3
or 𝐾 𝑥 = 𝐹 −1
then 𝑥 = 𝐾 𝐹
26
Solving Simultaneous Equation
in OO Calc Spreadsheet
𝑥1 4.1
The result: 𝑥2 = 1.1
𝑥3 −1.4 27
Solving Simultaneous Equation
in FreeMat
28
Cramer's Rule Method
−1 3 −2 𝑥1 2 2 3 −2
2 −4 2 𝑥2 = 1 ∣ 1 −4 2 ∣
0 4 1 𝑥3 3 𝑥1 = 3 4 1 = 4.1
−1 3 2
∣ 2 −4 2 ∣
0 4 1
−1 2 −2 −1 3 2
∣ 2 1 2 ∣ ∣ 2 −4 1 ∣
𝑥2 = 0 3 1 = 1.1 𝑥3 = 0 4 3 = 1.4
−1 3 2 −1 3 2
∣ 2 −4 2 ∣ ∣ 2 −4 2 ∣
0 4 1 0 4 1
29
Gauss Elimination
Gauss Elimination is based on triangularisation of the
coefficient matrix and evaluation of the unknowns by back-
substitution starting from the last equation
𝑎𝑖𝑘 𝑘 = 1,2, ⋯ , 𝑛 − 1
𝑎𝑖𝑗 = 𝑎𝑖𝑗 − 𝑎𝑘𝑗 𝑖 = 𝑘 + 1, ⋯ , 𝑛
𝑎𝑘𝑘
𝑗 = 𝑘, ⋯ , 𝑛 + 1
𝑛
1
𝑥𝑖 = 𝑎𝑖,𝑛+1 − 𝑎𝑖𝑟 𝑥𝑟
𝑎𝑖𝑖
𝑟=𝑖+1
30
Example Problem 2.2
2𝑥1 + 2𝑥2 + 1𝑥3 = 9
2𝑥1 + 1𝑥2 = 4
1𝑥1 + 1𝑥2 + 1𝑥3 = 6
a. Find the unknown variables x1, x2 and x3 from the
following equations, using Gauss Elimination Method
b. Verify the result in Speadsheet
Since the order of matrix is n=3, the index for solving this problem
𝑛=3
𝑘 = 1,2
𝑖 = 2,3
𝑗 = 1,2,3,4
31
𝑘 = 1,2, ⋯ , 𝑛 − 1 The running index will be (for n=3)
k=1
𝑖 = 𝑘 + 1, ⋯ , 𝑛 i=2
𝑗 = 𝑘, ⋯ , 𝑛 + 1 j = 1 to 4
Calculate aij
i.e. a21 a22 a23 a24
i=3
j = 1 to 4
Calculate aij
i.e. a31 a32 a33 a34
k=2
i=3
j = 2 to 4
Calculate aij
i.e. a32 a33 a34
32
The running index will be (for n=3)
2 2 1 k=1
𝑎 = 2 1 0 i=2
j = 1 to 4
1 1 1 Calculate aij
i.e. a21 a22 a23 a24
𝑎21 2
𝑎23 = 𝑎23 − 𝑎13 =0−1 = −1
𝑎11 2
𝑎21 2
𝑎24 = 𝑎24 − 𝑎14 =4−9 = −5
𝑎11 2
33
2 2 1 i=3
j = 1 to 4
𝑎 = 2 1 0 Calculate aij
1 1 1 i.e. a31 a32 a33 a34
𝑎31 1
𝑎33 = 𝑎33 − 𝑎13 =1−1 = 0.5
𝑎11 2
𝑎31 1
𝑎34 = 𝑎34 − 𝑎14 =6−9 = 1.5
𝑎11 2
34
2 2 1 k=2
i=3
𝑎 = 2 1 0 j = 2 to 4
1 1 1 Calculate aij
i.e. a32 a33 a34
𝑎32 0
𝑎𝑖𝑘 𝑎32 = 𝑎32 − 𝑎22 = 0 − −1 =0
𝑎𝑖𝑗 = 𝑎𝑖𝑗 − 𝑎𝑘𝑗 𝑎22 −1
𝑎𝑘𝑘
𝑎32 0
𝑎33 = 𝑎33 − 𝑎23 = 0.5 − −1 = 0.5
𝑎22 −1
𝑎32 0
𝑎34 = 𝑎34 − 𝑎24 = 1.5 − −5 = 1.5
𝑎22 −1
35
𝑛
1
𝑥𝑖 = 𝑎𝑖,𝑛+1 − 𝑎𝑖𝑟 𝑥𝑟
𝑎𝑖𝑖
𝑟=𝑖+1
1 1
𝑥3 = 𝑎34 − 0 = 1.5 = 3
𝑎33 0.5
1 1
𝑥2 = 𝑎24 − 𝑎23 𝑥3 = −5 − −1 3 =2
𝑎22 −1
1 1
𝑥1 = 𝑎14 − 𝑎12 𝑥2 − 𝑎13 𝑥3 = 9−2 2 −1 3 =1
𝑎11 2
36
Verification using inverse matrix in OO Spreadsheet
37
Gauss Siedel Iteration Method
1
𝑥1 = 𝑐1 − 𝑎12 𝑥2 − 𝑎13 𝑥3 − ⋯ − 𝑎1𝑛 𝑥𝑛
𝑎11
1
𝑥2 = 𝑐2 − 𝑎21 𝑥1 − 𝑎23 𝑥3 − ⋯ − 𝑎2𝑛 𝑥𝑛
𝑎22
⋮
1
𝑥𝑛 = 𝑐𝑛 − 𝑎𝑛1 𝑥1 − 𝑎𝑛2 𝑥2 − ⋯ − 𝑎𝑛,𝑛−1 𝑥𝑛−1
𝑎𝑛𝑛
𝑐𝑖
A good initial guess 𝑥𝑖 =
𝑎𝑖𝑖
38
Example Problem 2.3
4𝑥1 − 𝑥2 = 2
−𝑥1 + 4𝑥2 − 𝑥3 = 5
−𝑥2 + 4𝑥3 − 𝑥4 = 6
−𝑥3 + 2𝑥4 = −2
39
𝑐𝑖
4 −1 0 0 2 A good initial guess 𝑥𝑖 =
−1 4 −1 0 5 𝑎𝑖𝑖
𝑎 = 𝑐 = 𝑥1 = 0.5 𝑥3 = 1
0 −1 4 −1 6
0 0 −1 2 −2 𝑥2 = 1 𝑥4 = −1
42