MUMBERE MUYALI
BENEDICT
19/BCN/BU/R/1004
Matric
es
MATRIX NAMING
What is a matrix?
•A Matrix is just rectangular arrays of
items
•A typical matrix is a rectangular array of
numbers arranged in rows and columns.
21 62 33 93
A 44 95 66 13
3x4 77 38 79 33
Sizing a
• Bymatrix
convention matrices are “sized” using the
number of rows (m) by number of columns (n).
21 62 33 93 7 3 2
95 66 13 B 8 4
x 44
3A 3x3 1
4 6 9
77 38 79 33 5
11 4
C
14 7 D
4x 8 1x1
2 16
17
3
22
“Special” Matrices
• Square matrix: a square matrix is an mxn matrix in which m
=
n.
7 3
3x3 1
6 9
2
• Vector: a vector is an mxn matrix where either m OR n = 1
(but not both). B 8
12
9 Y 7 22
4X 4 4
x1 0 14
5 1x3
“Special”
• Scalar: a scalar is an mxn matrix where BOTH m and
Matrices
n = 1. D
1x1
0 0
17an mxn matrix of zeros. 0
• Zero matrix: 0
3x
2
0 0
0
• Identity Matrix: a square (mxm) matrix with 1s on
the diagonal and zeros everywhere else.
1 0
3 0
x3 0 1
0
I
Transposing a Matrix
• Matrix Transpose: is the mxn matrix obtained by
interchanging the rows and columns of a matrix
(converting it to an nxm matrix)
12
9
4X 4 X ' 12 9 4
1x 4 0
x1 0
21 44 77
21 62 33 93 62 95 38
44 95 66 13 A'
A
3x 4 x3
4 33 66
77 38 79 33 79
Matrix
•Addition
Matrices can be added (or subtracted) as long as the 2
matrices are the same size
• Simply add or subtract the corresponding components of
each matrix.
Matrix Multiplication
• Multiplying a matrix by a scalar: each
element in the matrix is multiplied by the
scalar.
2
A and x = 5;
2x
31
7 3
9 then
1x1
8 5*2 5*3 5 10
xA 5*9 35
5*7 45
5*1 15
Matrix
•Multiplication
Multiplying a matrix by a matrix:
• the product of matrices A and B (AB) is defined if
the number of columns in A equals the number
of rows in B.
• Assuming A has ixj dimensions and B has jxk
dimensions, the resulting matrix, C, will have
dimensions ixk
• In other words, in order to multiply them the
inner dimensions must match and the result is
the outer dimensions.
• Each element in C can by computed by:
Cik j Aij B jk
• Dimension: This is the size of a matrix (number
of rows by the number of columns)
• The example on the previous slide is a 3x4 matrix
written as B34
Matrix Multiplication
• Multiplying a matrix by a matrix:
5
1 2 3
B ' 3
A
2 x3 8 3x 4
7 9 6 7
2
5
Matching inner dimensions!!
AB' C c12
c113 x 2 2 x c 21
2 x3 c 22 Resulting matrix has outer dimensions!!!
2
c11 A1 j B j1 1*5 2 * 6 3* 7
38 c12 A1 j B j 2 1*3 2 * 4
3*5 26 c21 A2 j Bj1 7 *5 8*
26
A B ' C
62 x3 3x 2 9 2*x 7 c22 A2 j B j 2 7
238
155155 98
Reducing Square Matrices
• Trace: the sum of the diagonal of a square matrix.
7 3
1
3x3
6 9
2
tr(B) 7 4 9
B 8
20
Reducing Square Matrices
• Determinant:
• The determinant of a matrix is a scalar
representation of matrix; considered the
“volume” of the matrix or in the case of a VCV
matrix it is the generalized variance.
• Only square matrices have determinants.
• Determinants are also useful because they tell us
whether or not a matrix can be inverted (next).
• Not all square matrices can be inverted (must be
full rank, non-singular matrix)
Reducing Square
Matrices
• Determinant:
C 4
1x1 C
4 b1
2Cx C a1 *b2 b1 *
2 a 2 b2
a1
C 2 a2
C 3*1 2 *5 3 10
2 3 5 1
2x
7
Reducing Square Matrices
• Determinant:
a1 b1 c1 b2 a2 a2 2
2
C C c2 b c b b
3x3 2 c
b2 2 1 3 c3 1 a 3 c3 c 1
a b 3 c 3 a b a3 3
a
3
2
12
3x3
3 50
C
C 1 5 1* 4)2(1*5 1*3) 0(1*5 5*3
2(5*5
4
C 2(25 5)2(5 3) 0(5 15
Matrix Inverse
•Matrix Inverse: Needed to perform the
“division” of 2 square matrices
• In scalar terms A/B is the same as A * 1/B
• When we want to divide matrix A by matrix
B we simply multiply by A by the inverse of
B
• An inverse matrix is defined as
A A A
1 D ni fe de 1
I AND A 1
A I
nxn nxn nxn nxn nxn nxn nxn
Matrix Inverse
• Matrix Inverse: Needed to perform the
“division” of 2 square matrices
• In scalar terms A/B is the same as A * 1/B
• When we want to divide matrix A by matrix B we
simply multiply by A by the inverse of B
• An inverse matrix is defined as
A A A
1 D ni fe de 1
I AND A 1
A
I
nxn nxn nxn nxn nxn nxn
nxn
Matrix Inverse
• Matrix Inverse:
• For a 2x2 matrix the inverse is relatively simple
b1 1 a1 b 1
b
1
2Cx C
2 a 2 b2 C a
a1 2
3 2 x 2 7
2C
2
2Cx
2 5 1
2 3 2
1 1 3
5
7
1
7
C
7 5 1 7
DETERMINANT
• It only work for square matrices.
𝐴
• Determinant of a matrix A is defined by det(A) or
𝑎
𝑏 𝑐
𝐴 =
• Definition if A= is a 2x2 matrix then the determinant is given by
𝑑
ad-bc
• Example; find 3 2 note the straight lines tell you to find
5 4
the determinant
3 2
5 4 = 3x4-(-5x2) = 12+10 = 22.
Determinant of a 3x3
matrix
𝑎1 𝑏1
• Consider the matrix A= 𝑎2 𝑐1 find the determinant
𝑎3 𝑏2
𝑎1 𝑏1 𝑐1 𝑐22
𝑏 𝑎2 𝑎2
𝑏2 𝑐2 = 𝑎1 𝑏 𝑏233
𝑐 𝑐32 𝑏23
𝑎
𝑏1 𝑎3 𝑐 𝑐1
• Det(A) = - +
𝑎2 3 3
𝑐3𝑐
𝑐 𝑏3
𝑎 𝑏= 𝑎1𝑐(𝑏 2 𝑐3- 𝑐2 𝑏3)- 𝑏1(𝑎2 𝑐3- 𝑐2 𝑎3)+ 𝑐1(𝑎2
𝑏3- 𝑏2 𝑎3)
3
6 1
1
that 𝐴 = 2 8
4 −2
Given find
5
7
det(A).
6 1
Solution
−2 5 4 5 4 −2
• Det(A) = 1 −1 +1
5 = 8 7 2 7 2 8
−2
4 6
2 8
7
= 6(-2x7-8x5)-1(4x7-2x5)+1(4x8-2x-2)
−5 6 4
= 6x(-54)-1x18+1x36 = -306
Qn Solve for the determinant of a 3x3 matrix: P = 1 2
−3
−2 4 2
Inverse of a Matrix
• If two square matrices M and A have the property that MA = I, (in
infinite dimensions you also need the condition that AM = I) then A
and M are said to be inverses of one another and we write A =
M- 1 and M= A-1. NB I is an identity matrix.
• When we multiply a matrix by its inverse we get
the Identity Matrix (which is like "1" for matrices):
• i.e A × A-1 = I and it is also true that A-1 A = I
• Where A-1 is the inverse of A .
• Look at the 3x3 identity matrix.
How to calculate 2x2 matrix?
N.B To have an inverse
the matrix must be
• 𝑎 𝑏 −1 1 𝑑
• For a 2x2 matrix the inverse is:
"square" (same number
𝑐 −𝑐
−𝑏
=𝑎𝑑−𝑏
𝑎 𝑑
of rows and columns).
𝑐
𝑐 𝑎 −𝑏
But also
𝑑 𝑏
• i.e inverse of A= = 1/det(A)
𝑑 −𝑐 𝑎
the determinant
• Example: 3 5 −1 = 2
cannot be zero (or we
1
6 3𝑥2−5𝑥 −5
end up dividing by
2 6
−6 3 2
zero).
−5 1 5
2
= −24 = −12 24
−5 −24 1
= 1/-24
−6 3
−6
−24 3 −1
−24 4
8
HOW TO CALCULATE A 3X3
MATRIX
• We can calculate the Inverse of a Matrix by:
• Step 1: calculating the Matrix of Minors,
• Step 2: then turn that into the Matrix of Cofactors,
• Step 3: then the Adjugate, and
• Step 4: multiply that by 1/Determinant. WHAT YOU
GET IS THE INVERSE!!
Example:
3 0 2
• If the matrix A = 2 0
−2
, find its inverse;
0 1 1
• We start by creating a "Matrix of Minors“
• Procedure; For each element of the matrix:
• ignore the values on the current row and column,
calculate the determinant of the remaining
values
• Put those determinants into a matrix (the "Matrix of
Minors")
3 0 3 0 2 3 0 2
• = 2 0 −2 =0—2=2 2 0 −2 =3x1-2x0=3 2 0 −2
0 1 1 =0 1
0 1
1 0
3 0 2 3 0 2
•= 2 0 −2 =1x2—0x2=2 2 0
0 1 1 1
0
−2 1
=3x1-0x0 =3
1
3 0 3 0 2
• = 2 0 −2 =2x1-0x0=2 2 0
0 1 1 −2
= 0x-2-0x2=0
0 1 1
3 0 2 3 0 2
• = 2 0 −2 =0x1-2x1 =-2 2 0
−2 1
0
= 3x-2-2x2=-10
1 0 1 1
2 2
• Therefore the matrix of minors is 2
0
−2 3
Matrix of Minors
3
−10
+ 0 2 −2 2
other words, we need to change the sign of alternate
• Matrix of Cofactors: This is easy! Just2apply
3a
− −3
Matrix of
0 10 0
"checkerboard" of minuses to the "Matrix of Minors". In
CoFactors
+
•
− + − =
+
cells, like this:
−
Next step : Adjugate (also
called Adjoint)
• Now "Transpose" all elements of the previous matrix
(matrix of cofactors).
2 −2 2 2 −2
• Transpose of 2 3 = 0
−3 −2 3
• That is changing a0row10 10and a column into a row
into a0column
2 −3
0
• Lastly multiply the matrix of CoFactors by 1/Determinant. In practice
we just multiply each of the elements of the top row by the
cofactors. Elements of top row: 3, 0, 2
Cofactors for top row: 2, −2, 2
• Determinant = 3×2 + 0×(−2) + 2×2 = 10
• Just for fun; try this for any other row or column, they
should also get 10.
3 0 2 −2 0 0.2 −0.2
• Now find he inverse of the matrix.
−
1 1
2 1
0
• 2 0 −2 −2 3 10 −0.2 0.3
= =
0𝑥
0 1 1
1 2 −3 0 0.2 −0.3
0
• In particular, if det(𝐴) ≠ 0, then 𝑥𝑎𝑑𝑗
1
det
𝐴 −1 = 𝐴 .
• Where adj(A)= transporse of CoFactor𝐴matrix
1 3
.
• QN; Given that 𝐴 2
= −1 0 2
3 1
−1