Matrices

Definition and Terminology

Definition

A matrix is an array of mathematical objects. It could contain real numbers, complex numbers, functions even other matrices. For our purposes, we will focus on real numbers. We have seen vectors in various contexts in this course. One that we haven't focused on is vectors as representations of the vertices that make up an object defined by a polygonal mesh. In future chapters, we will look at how you can manipulate such an object by manipulating its vectors. These manipulations can be represented by matrices. We think of these matrices as operating on the vectors. But before we can get to all of that we need to aquint ourselves with what matrices are and how they behave algebraically.
We usually name a matrix with an uppercase letter and name its entries with the corresponding lower case letter.

(1)
\begin{align} A= \left [ \begin{array}{cccc} a_{11} & a_{12} & \cdots & a_{1n}\\ a_{21} & a_{22} & \cdots & a_{2n}\\ \cdots & \cdots & \cdots & \cdots \\ a_{m1} & a_{m2} & \cdots & a_{mn}\\ \end{array} \right ] \end{align}

The entry $a_{ij}$ refers to the entry in matrix $A$ in the ith row and jth column. For brevity we do not put a comma between the i and j values unless the number of columns or rows exceeds 9.

Exercise
For the matrix $A=\left [ \begin{array}{ccc} 5 & -0.12 & 8\\ 0 & \pi & \frac{1}{3}\\ -1 & -10 & -100 \\ \end{array} \right ]$ what would $a_{2,3}$ be?

Dimension

The dimension of a matrix refers to the number of columns a matrix has. A matrix with m rows and n columns is said to have dimension $m \times n$. The notation $A_{m \times n}$ is used to idicate a matrix named $A$ that has dimension $m \times n$.
A matrix that has the same number of rows as columns or in other words has dimension $n \times n$ is called a square matrix. The name refers to the fact that the matrix is square in shape.

Exercise
What is the dimension of the matrix $B=\left [ \begin{array}{cccc} -3 & -2 & 6 & 10\\ 0 & \pi & \frac{\pi}{3} & -1\\ \end{array} \right ]$ ?

Operations

Addition/Subtraction

In order to add or subtract two matrices with the same dimension, we add or subtract the corresponding entries. That is to say,

(2)
\begin{align} A\pm B=\{ a_{ij}\pm b_{ij} \} \end{align}

It is important that both matrices have the same dimension so that there is a corresponding entry to add or subtract. Otherwise, the operation is said to be undefined.

Exercise
Find the sum, $A+B$ and $A-B$ for $A= \left [ \begin{array}{ccc} 2 & -2 & 1 \\ 0 & 15 & 100\\ \end{array} \right ]$ and $B=\left [ \begin{array}{ccc} -3 & -2 & 6 \\ 0.4 & -5.3 & -1\\ \end{array} \right ]$

Exercise
Find the sum, $A+B$ and $A-B$ for $A= \left [ \begin{array}{cc} 5 & 8 \\ -9 & 5 \\ \end{array} \right ]$ and $B=\left [ \begin{array}{ccc} 3 & 6 & 7 \\ -8 & 0 & 1\\ \end{array} \right ]$

Scalar Multiplication

In order to multiply a matrix by a scalar, we multiply every entry in the matrix by the scalar. That is to say,

(3)
\begin{align} kA=\{ ka_{ij} \} \end{align}

Exercise
Find, 5$A$ where $A=\left [ \begin{array}{ccc} 4 & 0 & -2 \\ 6 & 1 & -0.2\\ \end{array} \right ]$

Matrix Multiplication

In order to multiply two matrices, we take the dot product of each row in the first matrix with each column in the second matrix. IN other words,

(4)
\begin{align} AB=\{c_{ij}\} \mbox{ where } c_{ij}=(\mbox{Row i of matrix A}) \cdot (\mbox{Row j of matrix B}) \end{align}

Example

(5)
\begin{align} \left [ \begin{array}{cc} 1 & 5\\ 2 & 8\\ \end{array} \right ] \left [ \begin{array}{cc} 3 & -7\\ 4 & 0\\ \end{array} \right ] = \left [ \begin{array}{cc} (1)(3)+(5)(4) & (1)(-7)+(5)(0)\\ (2)(3)+(8)(4) & (2)(-7)+(8)(0)\\ \end{array} \right ] \left [ \begin{array}{cc} 23 & -7\\ 38 & -14\\ \end{array} \right ] \end{align}

Note that in order for each row in matrix $A$ to be the same length as each column in matrix $B$, we must have their inner dimensions match. In other words $A_{p \times q}$ and $B_{q \times r}$. If that inner dimension $q$ does not match the operation is undefined.

Exercise
Find the products, $AB$ and $BA$ for $A= \left [ \begin{array}{ccc} 2 & -2 & 1 \\ 0 & 15 & 100\\ \end{array} \right ]$ and $B=\left [ \begin{array}{cc} -3 & -2 \\ 4 & -5\\ \end{array} \right ]$

Transpose

The transpose $(A^T)$ of a matrix $A$ is one in which each row in the original matrix becomes a column in the resulting matrix.

Example

(6)
\begin{align} A= \left [ \begin{array}{ccc} 2 & 6 & 8\\ -4 & 3 & 10\\ \end{array} \right ] \hskip 1in A^T= \left [ \begin{array}{cc} 2 & -4\\ 6 & 3\\ 8 & 10\\ \end{array} \right ] \end{align}

This operation can be useful as a way of changing the way vectors are represented in a matrix. Say for example you had a matrix that was storing vertices of an object as column vectors. This is the standard in OpenGL. If you needed to use this in Direct3D which uses row vectors you could change that representation to a matrix of row vectors instead.

Determinant

The determinant of a matrix is related to the content of the space spanned by the vectors that make up the matrix. It has many other uses as we have already seen in the calculation of the cross product and in Cramer's Rule. The definition of the determinant is recursive. The 3D determinant is based on the 2D determinant, the 4D determinant is based on the 3D determinant and so on. For our purposes, we will just focus on 1D, 2D, and 3D determinants.

1D

(7)
\begin{equation} |a|=a \end{equation}

Note that the absolute value of this determinant would just give the magnitude of the vector $\vec{u}=<a>$.

determinant1d.png

2D

(8)
\begin{align} \left | \begin{array}{cc} a & b\\ c & d\\ \end{array} \right | =ad-bc \end{align}

Note that the absolute value of this determinant would give the area of the parallelogram spanned by the vectors $\vec{u}=<a,b>$ and $\vec{v}=<c,d>$

determinantparallelogram.png

3D

(9)
\begin{align} \left | \begin{array}{ccc} a & b & c\\ d & e & f\\ g & h & i\\ \end{array} \right | =a \left | \begin{array}{cc} e & f\\ h & i\\ \end{array} \right | -b \left | \begin{array}{cc} d & f\\ g & i\\ \end{array} \right | +c \left | \begin{array}{cc} d & e\\ g & h\\ \end{array} \right | \end{align}

Note that the absolute value of this determinant would give you the volume of the parallelepiped spanned by $\vec{u}=<a,b,c>$, $\vec{v}=<d,e,f>$, and $\vec{w}=<g,h,i>$.

volume-of-parallelepiped-through-vectors.svg

Note that the determinant is only defined for square matrices.

Example

(10)
\begin{align} \left | \begin{array}{ccc} 1 & 4 & -2\\ 3 & 0 & 6\\ -7 & 8 & 5\\ \end{array} \right | =1 \left | \begin{array}{cc} 0 & 6\\ 8 & 5\\ \end{array} \right | -4 \left | \begin{array}{cc} 3 & 6\\ -7 & 5\\ \end{array} \right | +(-2) \left | \begin{array}{cc} 3 & 0\\ -7 & 8\\ \end{array} \right | =1(0-48)-4(15+42)-2(24-0)=-48-228-48=-324 \end{align}

Exercise
Find $|A|$ for the matrix $A=\left [ \begin{array}{ccc} 6 & -1 & 3\\ 2 & 4 & 5\\ -3 & 8 & 0\\ \end{array} \right ]$

Matrix Division and the Inverse

Using the previously mentioned operations we could solve equations whose unknowns are now matrices instead of real numbers. To do so we would use take our ideas from Algebra and apply them to matrices thereby defining a matrix algebra. As we know from algebra, solving equations involves applying the inverse operations in order to isolate the unknown quantity. In this case an unknown matrix. The problem we have is that we have yet to define the inverse of matrix multiplication. A matrix division if you will.
Recall from algebra that we accomplish division by multiplication of the reciprocal. The reciprocal is what we would call the multiplicative inverse. The multiplicative inverse is defined to be that number which when multiplied yield the multiplicative identity, 1. For example,

(11)
\begin{align} 4 \left ( \frac{1}{4} \right ) = 1 \end{align}

Therefore, the multiplicative inverse of $4$ is $\frac{1}{4}$ and vice versa. The nice thing about real numbers is that every real number has a multiplicative inverse, except 0. Therefore, we can divide by any number except 0.
If we were to define a matrix division, we would first need to determine the multiplicative identity for matrix multiplication. In other words, we would need to find the matrix $I$, such that for any matrix $A$,

(12)
\begin{equation} AI=IA=A \end{equation}

As you can confirm for yourself this identity matrix would need to be of the form,

(13)
\begin{align} I=\left [ \begin{array}{c} 1 \\\end{array} \right ] \\ I=\left [ \begin{array}{cc} 1 & 0 \\ 0 & 1 \\ \end{array} \right ] \\I=\left [ \begin{array}{ccc} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1\\ \end{array} \right ] \end{align}

So in general, you have an $n \times n$ matrix with ones on the diagonal and zeros everywhere else. So now the question is, given a matrix $A$ can we find its multiplicative inverse $A^{-1}$ such that,

(14)
\begin{equation} AA^{-1}=A^{-1}A=I \end{equation}

If we can find such a matrix, we could solve a matrix algebra question, such as,

(15)
\begin{equation} Ax=B \end{equation}

by applying the inverse matrix to the left side of both sides of the equation, as follows.

(16)
\begin{align} A^{-1}Ax=A^{-1}B\\ Ix=A^{-1}B\\ x=A^{-1}B \end{align}

As it turns out, unlike the real numbers, there are many matrices that have no multiplicative inverse. Actually, the invertibility of a matrix can be determined by its determinant. If $|A|=0$ the matrix has no inverse. For our purposes in this class, we do not need to do matrix division, so we will not go into the process of finding the inverse of a matrix. The process is rather involved. If you would like to know more, check out this video

Exercises

1) Given the matrices

(17)
\begin{align} A=\left [ \begin{array}{cc} 1 & 4 \\ -3 & 8 \\ \end{array} \right ] \mbox{ and } B= \left [ \begin{array}{cc} 6 & 2 \\ 0 & -5 \\ \end{array} \right ] \end{align}

a) Find $2A-3B$
b) Find $AB$
c) Find $BA$
d) Find $A^T$

2) Given the matrices

(18)
\begin{align} A=\left [ \begin{array}{ccc} 0 & -7 & 2\\ 1 & 4 & 9 \\ \end{array} \right ] \mbox{ and } B= \left [ \begin{array}{cc} 5 & 1 \\ 2 & 8 \\ 4 & -3 \\ \end{array} \right ] \end{align}

a) Find $AB$
b) Find $BA$

3) Find $|A|$ for the matrix

(19)
\begin{align} A=\left [ \begin{array}{ccc} 5 & 8 & 16 \\ -2 & -9 & -11 \\ 0 & 4 & 1 \\ \end{array} \right ] \end{align}

4) Find $|B|$ for the matrix and sketch a picture of the volume it represents.

(20)
\begin{align} B=\left [ \begin{array}{ccc} 6 & 0 & 0 \\ 0 & 4 & 0 \\ 0 & 0 & 3 \\ \end{array} \right ] \end{align}

5) If $A_{5 \times 7}$, what dimensions must $B$ have in order for $AB$ to be defined?

6) If $A_{5 \times 7}$, what dimensions must $B$ have in order for $BA$ to be defined?

7) Given two n-dimensional vectors $\vec{u}$ and $\vec{v}$, say we represent them as two $n \times 1$ matrices $U$ and $V$. How would we calculate the dot product of $\vec{u}$ and $\vec{v}$, using matrix operations on $U$ and $V$.

8) Verify with matrix multiplication that if $A=\left [ \begin{array}{cc} 2 & -14 \\ 6 & -43 \\ \end{array} \right ]$ , then $A^{-1}=\left [ \begin{array}{cc} \frac{43}{2} & 7 \\ 3 & 1 \\ \end{array} \right ]$

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License