Matrix Algebra Slides Class Notes V5 S010 Week 13 B Apr 8
Matrix Algebra Slides Class Notes V5 S010 Week 13 B Apr 8
Matrices
Matrices are used to perform transformations, rotation and scaling of objects in computer graphics.
This allows us to take any points in space (an object is made up of many points), and move these
points (in turn moving the object) by rotating it, shrinking it, stretching it, whatever we’d like. We
will talk more about this in the module Matrix Transformations.
What is a matrix?
An n × m matrix is an array of numbers (each called an element) with n rows and m columns. For
example, a 2 ×3 matrix (let’s call it matrix A) is set up in the following way:
A=
[ a11 a12 a13
a 21 a22 a23](a a a
= 11 12 13
a21 a22 a23 )
Example 1: What are the dimensions of the following matrices?
[]
1
a) A= [
1 2 3 4
2 −1 5 2 ] b) B=[1 −1
2 −3 ] c) C=
−2
3
4
[ ] [ ]
1 0 0 5 2 0
d) D= 0 1 0 e) E= 2 1 −1 f) F=[ 1 0 0 0]
0 0 1 0 0 1
g) Square Matrix definition: A square matrix has the same number of rows and columns
i) Row Matrix definition: If the matrix has only one row, then it’s a row matrix.
j) Column Matrix definition: If the matrix has only one column, then it is a column matrix.
k) Zero matrix definition: If all the elements of a matrix are zeros, then it’s a zero matrix.
[]
a1
a2
A= a 3
a4
⋮
an
is often used to represent a vector. If we have a vector, say ⃗v , in 2 dimensions where the vector has
its tail at the origin and the head at the point (x , y ), we know that this vector can be represented by
⃗v =[ x , y ]. This vector is being represented as a row matrix. More often you will see a vector being
2
Module: Matrix Algebra
Example 3: Can we add a 2 ×2 matrix with a 3 ×3 matrix? They are both square matrices!
[ ]
1 0 0
a) [ 1 2 3 4
2 −1 5 2 ]
and 0 1 0
0 0 1
[ ] [ ]
5 2 0 1 0 0
b) 2 1 −1 and 0 1 0
0 0 1 0 0 1
c) [ 21 −21 ] [ 12 −1
and
−3 ]
[]
1
−2
d) and [ 1 0 0 0 ]
3
4
How do we add/subtract matrices? The sum is defined as the matrix consisting of the sums of the
corresponding elements.
a) [ 21 −21 ] [ 12 −1
+
−3 ]
b) [ 21 −21 ]−¿ [ 10 −3
−1
]
3
Module: Matrix Algebra
[ ][ ] [ ][ ]
5 2 0 1 0 0 5 2 0 1 2 0
c) 2 1 −1 + 0 1 0 d) 2 1 −1 −¿ 0 −1 0
0 0 1 0 0 1 0 0 1 0 3 1
[ ][ ]
1 0
e) [ 22 ][
1 0+1 2 3 4
3 1 2 −1 5 2 ] f)
−2 − 0
3 3
4 −2
4
Module: Matrix Algebra
[
A= 2 −1 , B= 0
1 3 ] [ ] [
2 , C= 1 −2
−2 −4 −1 −4 ]
find the following:
a) 2A b) ½ B
[
A= 2 −1 , B= 0
1 3 ] [ ] [
2 , C= 1 −2
−2 −4 −1 −4 ]
c) 3C
5
Module: Matrix Algebra
[ ] [
A= 2 −1 , B= 0
1 3 ] [
2 , C= 1 −2
−2 −4 −1 −4 ]
d) 2A−3 C
6
Module: Matrix Algebra
A=
[ 21 −13 ] , B=[−20 −42 ] , C=[−11 −2
−4 ]
e) 2(A+B−C ¿
7
Module: Matrix Algebra
Equivalent Matrices
Two matrices are said to be equal if every corresponding element is identical.
Example 7:
[ 12 2 3 4
−1 5 2
and ] [
1 2 3 4
2 −1 5 1 ]
Example 8: Find the value of each variable such that the equation is true.
8
Module: Matrix Algebra
Find the value of each variable such that the equation is true.
9
Module: Matrix Algebra
10
Module: Matrix Algebra
Multiply Matrices
There is a special way to multiply matrices. Note that we do NOT just multiply each corresponding
element.
We can only multiply two matrices where the number of columns of the first matrix is EQUAL to the
number of rows of the second matrix.
1. Make sure the # of columns in the first matrix = # of rows in the second matrix
2. Multiply the elements of each row of the first matrix by the elements of each column in the
second matrix.
3. Add the products.
Example 9: Can we multiply the following matrices? What size of matrix do we end up with?
11
Module: Matrix Algebra
][ ]
2 2
c) [ 1 −1 2
0 2 −2
3 −1
−2 4
][ ]
2 2
d) [
1 2 3 4
2 −1 5 1
3 −1
−2 4
[ ][ ]
1 2 0 1
e) 0 −1 0 −3
0 3 1 2
12
Module: Matrix Algebra
Note: Matrix multiplication is NOT commutative. What does that mean? If A and B are matrices
where the product can be taken, in most cases, AB≠ BA .
Example 11: Show why the following matrices do not commute (explain why AB≠ BA ).
[ ] []
1 2 0 1
a) A= 0 −1 0 , B= −3
0 3 1 2
AB=
[13 02][−12 −21 ]
[ 4 −4 ]
AB= 2 −2
[ ][ ]
BA= 2 −2 1 0
−1 1 3 2
BA=[
2 ]
−4 −4
2
13
Module: Matrix Algebra
Transpose of a Matrix
Finding the transpose of a matrix means taking each column of a matrix and turning it into the row
of a new matrix, or vise-versa. This can sometimes be used to calculate, for example, the dot
product a different way.
Example 13: If A= [ 23 14 ] T
, then A = [21 34 ] .
Example 14:
[ ]
2 3
a) If A= 4 −1 , then find AT
7 6
[ ]
1 2 0
b) If A= 0 −1 0 , then find AT
0 3 1
14
Module: Matrix Algebra
The identity matrix, I is a square matrix with 1’s for elements on its principal diagonal, with all other
elements being zero.
[ ]
Diagonal is all 1’s
1 0 0 ⋯ 0
0 1 0 ⋯ 0 Every other element is 0
I= 0 0 1 ⋯ 0
0 ⋮ ⋮ ⋱ 0
0 0 0 ⋯ 1
The identity matrix I behaves like 1 in arithmetic multiplication. The identity matrix multiplied by any
other square matrix results in the same matrix.
AI =IA =A
Show that AI =A
15
Module: Matrix Algebra
Inverse of a Matrix
If we have a square matrix A , then the inverse of that matrix is denoted A−1, and has the following
property
One of the reasons we use matrix inverses is to solve equations. The “typical” way of solving
equations doesn’t always apply with matrices. For example, if 2 x=4 , we solve this by dividing by 2,
and the answer is 4/2=2. We can’t do this when the coefficients and variables are matrices.
What do we do?
If A is a square matrix, B is a matrix where AB exists and C is the product of the two matrices,
meaning
AB=C ,
B= A−1 C
This means that if we want to solve for B we need to take the inverse of A in order to move it to the
other side of the equation. Therefore, in order to solve, we need to be able to find the inverse of a
matrix.
How do we compute the inverse of a matrix? We first need to discuss another matrix operation.
Determinant of a 2 ×2Matrix
The determinant of a matrix is used as an indicator whether a matrix has an inverse. If det A=0 ,
then that means the matrix A is NOT invertible (meaning it doesn’t have an inverse). Note that a
matrix MUST be square if want to compute the determinant, and the inverse must exist if we want
to solve for the matrix B in AB=C from above.
16
Module: Matrix Algebra
det
| || |
a1 a2 a1 a2
=
b1 b2 b1 b2
=a1 b 2−b1 a2
The determinant equals the multiplication of the principal diagonal a 1 b2 minus the multiplication of
the off-diagonals b 1 a2 .
Example 16: Do the following matrices have an inverse (are they invertible)? Compute the
determinant of the 2 ×2 matrices.
a) If A= [ 13 −2
−2 ]
, find ¿ A∨¿. b) If A=[−53 −23 ] , find det A .
c) If B=¿ [ 84 −4
−2 ]
, find ¿ B∨¿ . d) If B=¿ [−10 −4
−2 ]
, find ¿ B∨¿ .
17
Module: Matrix Algebra
The determinant of a 3 ×3 matrix or higher is also possible, but we will only be looking at 2 ×2
systems. Note: the procedure we use to calculate the cross product of vectors is actually doing the
determinant of a 3 ×3 matrix!
Inverse of a 2 ×2Matrix
In order to find the inverse of a 2 ×2matrix, we need to be able to compute the determinant.
[ ]
If A=
a1 a2
b1 b2
−1
,then A =
1
[b2 −a2
det A −b1 a1 ]
The inverse of a matrix A is the reciprocal of the determinant of A multiplied by a new matrix
where the principal diagonals of A are switched and the off-diagonals of A are changed signs.
a) A= [ 13 −2
−2 ]
, find A−1 b) If B= [−53 −23 ] , find B−1
18
Module: Matrix Algebra
[ ]
If A=
a1 a2
b1 b2
−1
,then A =
1
det [
A
b2 −a2
−b1 a1 ]
c) C= [ 84 −4
−2 ]
, find C−1 d) D= [−10 −4
−2 ]
find D −1
19
Module: Matrix Algebra
Now we can use the inverse in order to solve for equations involving matrices. Remember:
20
Module: Matrix Algebra
21
Module: Matrix Algebra
22