Professional Documents
Culture Documents
Matrices 2
Matrices 2
1 Why
2 Matrix arithmetic
1 Transpose
2 Addition
3 Multiplication
4 Determinant
5 Inverse
6 Eigenvalues and Eigenvectors
Grace K. Goka 1 / 65
Why?
Graph theory
1 communications network
2 transportation systems
Graphic software
Cryptography
Grace K. Goka 2 / 65
Matrices
Definition
A matrix is a rectangular array of numbers. A matrix with m rows and n
columns where m and n are positive integers is called an m × n matrix.
a11 a12 · · · a1n
a21 a22 · · · a2n
Am,n = .
.. .. ..
.. . . .
am1 am2 · · · amn
Rows are counted from the top to down and columns from the left to right.
1 1
The matrix 0 2
1 3
is a 3 × 2 matrix(dimension of the matrix).
Grace K. Goka 3 / 65
Types of Matrices
Some matrices have special names because of what they look like.
Square Matrix
0 2 5
1 1 1 3 7
0 2
1 2 3
Grace K. Goka 4 / 65
Zero Matrix
A matrix in which each entry
iszero is calleda zero-matrix,
denoted O.
0 0 0 0 0
0 0
A= , B = 0 0 , B = 0 0 0
0 0
0 0 0 0 0
Diagonal Matrix
A square matrix in whichthe entriesoutside the main diagonal are all zero
1 0 0
a 0
A= , B = 0 −5 0
0 b
0 0 8
Grace K. Goka 5 / 65
Lower Triangular Matrix
A square matrix is called lower triangular if all the entries above the main
diagonal are zero.
1 0 0
a 0
A= , B = 6 −5 0
c b
3 2 8
Non-negative Matrix
A rectangular matrix A is called nonnegative if aij ≥ 0 for all i, j
Grace K. Goka 6 / 65
Positive Matrix
A rectangular matrix A is called Positive if aij > 0 for all i, j
Equal matrices
Two matrices are equal if they have the same size and their corresponding
entries
are equal.
1 2 1 2
A= ,B=
3 4 3 4
A= B
1 2 2 1
A= ,B=
3 4 3 4
A 6= B
1 2
1 2
A= , B = 3 4
3 4
a b
A 6= B
Grace K. Goka 7 / 65
Matrix Arithmetic
Transpose
Transpose of m × n matrix A, denoted AT , is n × m matrix with
Example
If
1 1 1 1
T 1 0 1
A = 0 2 , then A = and (AT )T = 0 2
1 2 3
1 3 1 3
a b c a d g
If A = d e f then AT b e h
g h k c f k
Grace K. Goka 8 / 65
Matrix Arithmetic
Laws of Transpose
1 (AT )T = A
2 (A ± B)T = AT ± B T
3 (cA)T = cAT
4 (AB)T = B T AT
5 If A is symmetric then A = AT
6 If A is symmetric then A2 and An are also symmetric
Grace K. Goka 9 / 65
Matrix Arithmetic
example
0 3 0 −3
The matrix A = is skew-symmetric because AT =
−3 0 3 0
example
1 1 0 1 1 0
The matrix A = 1 0 1 is symmetric because AT = 1 0 1
0 1 0 0 1 0
Grace K. Goka 10 / 65
Matrix Arithmetic
Grace K. Goka 11 / 65
Matrices
Exercises
Find the transpose of the following matrices and determine which ones are
symmetric.
2 3 0 2 3 0
1 5 2
A= B = 3 2 7 C = 1 8 7
3 0 7
0 7 2 0 1 5
Show that (AT )T = A
Grace K. Goka 12 / 65
Matrix Arithmetic
Addition
Let A = [aij ] and B = [bij ] be m × n matrices. The sum of A and B,
denoted by A + B, is the m × n matrix that has aij + bij as its (i, j)th
element. In other words, A + B = [aij + bij ].
Grace K. Goka 13 / 65
Matrices
Exercises
Let
1 2 7 2 8
1 1
A= , B = 3 4, C = 1 4 3
0 1
5 6 7 8 0
−8 0 0 0 5
5 −1
D = 5 7, E = , F = −1 1 −1
−1 5
−1 6 5 1 0
Find (if possible)
1 A+B
2 A+E
3 B+F
4 C+F
5 B+D
6 C+B
Grace K. Goka 14 / 65
Matrix
Theorem -Addition
If A, B, C are matrices and α, β ∈ R then
1 A + B = B + A Commutativity
2 A + (B + C ) = (A + B) + C Associativity
3 α(A + B) = αA + αB
4 If B = 0 then A + B = A + 0 = A
Grace K. Goka 15 / 65
Matrix Multiplication
Scalar Multiplication
Suppose that the matrix
a11 a12 · · · a1n ca11 ca12 · · · ca1n
a21 a22 · · · a2n ca21 ca22 · · · ca2n
A= . .. , then cA = ..
.. .. .. .. ..
.. . . . . . . .
am1 am2 · · · amn cam1 cam2 · · · camn
where c ∈ R
Example
Let
7 2 8 5×7 5×2 5×8 35 10 40
A = 1 4 3, then 5A = 5 × 1 5 × 4 5 × 3 = 5 20 15
7 8 0 5×7 5×8 5×0 35 40 0
Grace K. Goka 16 / 65
Matrix
Theorem -Addition
If A, B are matrices and α, β ∈ R then
1 α(βA) = (αβ)A
2 0A = 0
3 α0 = 0
Grace K. Goka 17 / 65
Matrix arithmetic
Grace K. Goka 18 / 65
matrix arithmetic
example
Let
1 0 4
2 1 1 2 4
A= 3 1 0, B = 1 1 .Find AB and BA if they are defined.
3 0
0 2 2
solution: Because A is a 4 × 3 matrix and B is a 3 × 2 matrix, the
productAB is defined and is a 4 × 2 matrix.
(1 × 2) + (0 × 1) + (4 × 3) (1 × 4) + (0 × 1) + (4 × 0)
(2 × 2) + (1 × 1) + (1 × 3) (2 × 4) + (1 × 1) + (1 × 0)
AB = (3 × 2) + (1 × 1) + (0 × 3) (3 × 4) + (1 × 1) + (0 × 0) =
(0 × 2) + (2 × 1) + (2 × 3) (0 × 4) + (2 × 1) + (2 × 0)
14 4
8 9
7 13.
8 2
If both A and B are bit matrices, then × = ∧ and + = ∨ in their boolean
product Grace K. Goka 19 / 65
Matrices
Exercises
Let
1 2 7 2 8
1 1
A= , B = 3 4, C = 1 4 3
0 1
5 6 7 8 0
−8 0 0 0 5
5 −1
D = 5 7, E = , F = −1 1 −1
−1 5
−1 6 5 1 0
Find (if possible)
1 AB and BA
2 AE and EA
3 BF and FA
4 CF and FC
5 BD and BD
6 CB and BC
Grace K. Goka 20 / 65
Matrix Multiplication
Theorem -Multiplication
If A, B, C are matrices and α, β ∈ R then
1 A(BC ) = (AB)C
2 A(B ± C ) = AB ± AC
3 AI = IA = A
4 c(AB) = (cA)B
5 α(βA) = αβA
6 0A = 0
7 For a square matrix A, Ar As = As Ar , r , s ≥ 1
Grace K. Goka 21 / 65
Definition
The identity matrix of order n is the n × n matrix In = [δij ], where δij = 1
if i = j and δij = 0 if i 6= j.
examples
1 0 0 0
1 0 0
1 0 0 1 0 0
I2 = , I3 = 0 1 0, I4 =
0 1 0 0 1 0
0 0 1
0 0 0 1
Grace K. Goka 22 / 65
matrix arithmetic
Definition
The inverse of a matrix A is A−1 such that AA−1 = I
Grace K. Goka 23 / 65
matrix arithmetic
Exercises
Let
1 1 1 2 5 7 5 −1
A= , B= D= , E=
0 1 3 4 −1 6 −1 5
Find (if possible)
A−1 , B −1 , D −1 , E −1
solution:
det(A) =(1 × 1) − (1 × 0) = 1 − 0 = 1
1 −1
adj(A)=
0 1
Hence
−1 1 1 −1 1 −1
A =1 =
0 1 0 1
Grace K. Goka 24 / 65
matrix arithmetic
Exercises
solution:
det(B) = (1 × 4) −
(2 × 3) = 4 − 6 = −2
4 −2
adj(B) =
−3 1
1 1
4 −2 4 × −2 −2 × −2 −2 1
B −1 = −2
1
= 1 1 = 3 1
−3 1 −3 × −2 1 × −2 2 −2
Grace K. Goka 25 / 65
Determinant
Rules of Determinant
1 If any two rows of A are interchanged to obtain B, then
det(B) = −det(A)
2 If any row is multiplied by a constant c, the resulting matrix B has
determinant det(B) = cdet(A)
3 If any two rows of A are equal, det(A) = 0
4 detAB = (detA)(detB)
Grace K. Goka 26 / 65
Determinant
Determinant of a 3 × 3
the determinant of a 3 × 3 matrix:
To work out
a b c
d e f
g h i
1 Multiply a by the determinant of the 2 × 2 matrix that is not in a’s
row or column.
2 Likewise for b, and for c
3 Add them up, but remember that b has a negative sign
Grace K. Goka 27 / 65
Determinant of 3 × 3 (Laplace expansion)
As a formula
a b c
e f d f d e
det(A) or |A| = d e f = a −b +c
h i g i g h
g h i
|A| = a(ei − fh) − b(di − fg ) + c(dh − eg )
Any matrix has a unique inverse if its determinant is nonzero (Non-
singular or invertible) and singular or nonivertible if the determinant is
zero.
Grace K. Goka 28 / 65
Determinant of 3 × 3 matrices
Grace K. Goka 29 / 65
Inverse of Matrix
example
Find
the inverse of the
matrix
1 0 4
A = −1 2 2
0 −2 −3
Grace K. Goka 30 / 65
Inverse of a matrix
Determinant
2 2 −1 2 −1 2
|A| = 1 −0 +4
−2 −3 0 −3 0 −2
|A| = 1(−6 + 4) + 4(2 − 0) = −2 + 8 = 6
Matrix of Minors
1 ignore the values on the current row and column
2 2 −1 2 −1 2
−2 −3 = −2 0 −3 = 3 0 −2 = 2
0 4 1 4 = −3 1 0 = −2
−2 −3 = 8 0 −3 0 −2
0 4 = −8 1 4 =6 1 0 =2
22 −1 2 −1 2
−2 3 2
Hence the matrix of minors is 8 −3 −2
−8 6 2
Grace K. Goka 31 / 65
Inverse of matrix
Cofactor matrix
+−+
Apply a ”checkerboard” of pluses and minuses− + − to the matrix of
+−+
minors to get the cofactor matrix.
So the cofactor
matrix for the matrix is
−2 −3 2
−8 −3 2
−8 −6 2
Adjugate
Transpose
the cofactor matrix
to get the adjoint of the matrix.
−2 −8 −8
Adj(A) = −3 −3 −6
2 2 2
Grace K. Goka 32 / 65
Inverse of a matrix
Inverse
Multiply the inverse of the determinant by the adjoint to obtain the
inverse of the matrix
−2 −8 −8
A−1 = |A|1
adj(A) = 61 −3 −3 −6
2 2 2
Leavingyour answer in this form makes it incomplete.
1 1 1
−2 × 6 −8 × 6 −8 × 6
A−1 = −3 × 61 −3 × 16 −6 × 16
2 × 16 2 × 61 2 × 16
1
− 3 − 43 − 43
= − 1 − 1 −1
2 2
1 1 1
3 3 3
Grace K. Goka 33 / 65
Inverse of matrix
Conclusion
1 find the determinant of the matrix
2 For each element, calculate the determinant of the values not on the
row or column, to get the Matrix of Minors
3 Apply a ”checkerboard” of minuses to make the Matrix of Cofactors
4 Transpose to obtain the adjoint
5 Multiply by 1/Determinant to get the inverse
Tryout
Find
the inverse of the
followingmatrices
1 0 4 −1 3 5 4 7 6
A = −1 2 2 , B= 2 2 −3 C = −2 4 0
0 −2 −3 2 −3 0 5 7 −4
Grace K. Goka 34 / 65
System of linear equations
A system of linear equations is a set of linear equations with the same
variables.
Grace K. Goka 35 / 65
System of linear equations
Grace K. Goka 36 / 65
System of linear equations
Grace K. Goka 37 / 65
System of linear equations
Algorithm
There are several algorithms for solving a system of linear equations.
1 Substitution
2 Graphing
3 Inverse of matrix
4 Row Reduction (Gaussian elimination): the linear system is
represented as an augmented matrix which is then modified using
elementary row operation to obtain echelon form.
example
Find the solution set for the system
x −y =3 (1)
x +y =7 (2)
Grace K. Goka 38 / 65
System of linear equations
x1 b1
a11 · · · a1n x2 b2
.. .. .. × = The system can also be represented in
. . . . .
.. ..
am1 · · · amn
xm bm
the form
A~x = ~b
~x = A−1 ~b
Grace K. Goka 39 / 65
System of linear equations
Find the solution set
x −y = 3
x +y = 7
Grace K. Goka 40 / 65
System of Linear Equations
Solve the system of equations
x + 2y + z = 1 (3)
2x + 3y + z = 4
3x + 4y + 2z = 4
This system can be put in the form Ax = b
1 2 1 x 1
2 3 1 y = 4
3 4 2 z 4
−1
x 1 2 1 1
y = 2 3 1 4
z 3 4 2 4
x −2 0 1 1 2
y = 1 1 −1 4 = 1
z 1 −2 1 4 −3
Grace K. Goka 41 / 65
System of Linear Equations
We could equally use python to solve this system by using the function
linalg .solve(A, b) where A is the coefficient matrix and b is the output
vector
x = 2, y = 1, z = −3
Grace K. Goka 42 / 65
System of Linear Equations
Solve the system of equations
3x + 2y + z = 7 (4)
x − 2y − z = 1
x + 3z = 11
Solution: This system can be put in the form Ax = b
3 2 1 x 7
1 −2 −1 y = 1
1 0 3 z 11
Grace K. Goka 43 / 65
System of Linear Equations
Solve the system of equations
x + 3y + 2z = 14 (5)
2x + y + z =
3x + 2y − z = 7
Solution: This system can be put in the form Ax = b
1 3 2 x 14
2 1 1 y = 7
3 2 −1 z 7
Grace K. Goka
x = 1, y = 3, z =2 44 / 65
Assiggnment
Grace K. Goka 45 / 65
Eigenvalue and Eigenvector
A matrix is an example of linear transform : transforms one vector
”linearly” into another. A~x = λ~x
Grace K. Goka 46 / 65
Eigenvalue and Eigenvector
Grace K. Goka 47 / 65
Eigenvalue and Eigenvector
A~x = λ~x
A~x − λ~x = 0
(A − λI )~x = 0
|A − λI | = 0 = P(λ) (6)
Grace K. Goka 48 / 65
Eigenvalue and Eigenvector
Find the
P(λ) - characteristic polynomial
spectrum of the matrices below
3 6 −8
1 1 1 5
case I: A = case II: B = case III:C = 0 0 6
3 −1 3 3
0 0 2
Soln:
P(λ) = |A − λI |
1 1 1 0
= −λ
3 −1 0 1
1 1 λ 0
= −
3 −1 0 λ
1−λ 1
=
3 −1 − λ
Grace K. Goka 49 / 65
Eigenvalue and Eigenvector
P(λ) = 0
2
λ −4 = 0
λ2 = 4
λ = ±2
Grace K. Goka 50 / 65
Eigenvalue and Eigenvector
P(λ) = |B − λI |
1 5 1 0
= −λ
3 3 0 1
1 5 λ 0
= −
3 3 0 λ
1−λ 5
=
3 3−λ
= (1 − λ)(3 − λ) − (3)(5)
= 3 − λ − 3λ + λ2 − 15
= λ2 − 4λ − 12
Grace K. Goka 51 / 65
Eigenvalue and Eigenvector
P(λ) = 0
2
λ − 4λ − 12 = 0
(λ + 2)(λ − 6) = 0
λ = −2, 6
Grace K. Goka 52 / 65
Eigenvalue and Eigenvector
To find the characteristic polynomial of matrix C
P(λ) = |C − λI |
3 6 −8 1 0 0
= 0 0 6 −λ 0 1
0
0 0 2 0 0 1
3 6 −8 λ 0 0
= 0 0 6 − 0 λ 0
0 0 2 0 0 λ
3−λ 6 −8
= 0 −λ 6
0 0 2−λ
P(λ) = (3 − λ)(−λ)(2 − λ) + (6)(6)(0) + (−8)(0)(0) − (−8)(−λ)(0) −
(3 − λ)(6)(0) − (6)(0)(2 − λ)
P(λ) = −λ(2 − λ)(3 − λ)
Grace K. Goka 53 / 65
Eigenvalue and Eigenvector
P(λ) = 0
−λ(2 − λ)(3 − λ) = 0
λ = 0, 2, 3
Grace K. Goka 54 / 65
Eigenvalue and Eigenvector
(A − λI )~x = 0
Grace K. Goka 55 / 65
Eigenvalue and Eigenvector
Case I:
when λ = 2
(A − 2I )~x = 0
1 1 1 0 x1 0
−2 =
3 −1 0 1 x2 0
1 1 2 0 x1 0
− =
3 −1 0 2 x2 0
−1 1 x1 0
=
3 −3 x2 0
using row 1,
−x1 + x2 = 0
1 × x1 = 1 × x2
x1 = 1, x2 = 1,
1
~xλ=2 =
Grace K. Goka
1 56 / 65
Eigenvalues and Eigenvectors
when λ = −2
(A − (−2)I )~x = 0
1 1 1 0 x1 0
− (−2) =
3 −1 0 1 x2 0
1 1 −2 0 x1 0
− =
3 −1 0 −2 x2 0
3 1 x1 0
=
3 1 x2 0
using row 1,
3x1 + x2 = 0
3 × x1 = −1 × x2
x1 = −1, x2 = 3,
−1
~xλ=−2 =
3
Grace K. Goka 57 / 65
Eigenvalues and Eigenvectors
Grace K. Goka 58 / 65
Eigenvalue and Eigenvector
Case II:
when λ = 6
(A − 6I )~x = 0
1 5 1 0 x1 0
−6 =
3 3 0 1 x2 0
1 5 6 0 x1 0
− =
3 3 0 6 x2 0
−5 5 x1 0
=
3 −3 x2 0
using row 1,
−5x1 + 5x2 = 0
1 × x1 = 1 × x2
x1 = 1, x2 = 1,
1
~xλ=6 =
Grace K. Goka
1 59 / 65
Eigenvalue and Eigenvector
when λ = −2
(A − (−2)I )~x = 0
1 5 1 0 x1 0
− (−2) =
3 3 0 1 x2 0
1 5 −2 0 x1 0
− =
3 3 0 −2 x2 0
3 5 x1 0
=
3 5 x2 0
using row 1,
3x1 + 5x2 = 0
3 × x1 = −5 × x2
x1 = −5, x2 = 3,
−5
~xλ=−2 =
3
Grace K. Goka 60 / 65
Eigenvalues and Eigenvectors
Grace K. Goka 61 / 65
Eigenvalues and Eigenvectors
Case III:
when λ = 0
(A − 0I )~x = 0
3 6 −8 1 0 0 x1 0
0 0 6 − 0 0 1 0 x2 = 0
0 0 2 0 0 1 x3 0
3 6 −8 0 0 0 x1 0
0 0 6 − 0 0 0 x2 = 0
0 0 2 0 0 0 x3 0
3 6 −8 x1 0
0 0 6 x2 = 0
0 0 2 x3 0
using row 3,
2x3 = 0
x3 = 0
Grace K. Goka 62 / 65
Eigenvalues and Eigenvectors
using row 1,
Grace K. Goka 63 / 65
Eigenvalues and Eigenvectors
when λ = 2
(A − 0I )~x = 2
3 6 −8 1 0 0 x1 0
0 0 6 − 2 0 1 0 x2 = 0
0 0 2 0 0 1 x3 0
3 6 −8 2 0 0 x1 0
0 0 6 − 0 2 0 x2 = 0
0 0 2 0 0 2 x3 0
1 6 −8 x1 0
0 −2 6 x2 = 0
0 0 0 x3 0
using row 2,
−2x2 + 6x3 = 0
−2x2 = −6x3
x2 = 3x3
Grace K. Goka 64 / 65
Eigenvalues and Eigenvectors
1 × x2 = 3 × x3
x2 = 3, x3 = 1
using row 1,
x1 + 6x2 − 8x3 = 0
3x1 + 6(3) − 8(1) = 0
x1 + 18 − 8 = 0
x1 = −10
−10
~xλ=2 = 3
1