Tutorial: Inventory of Matrices in 2D and 3D

Introduction

Vectors can be considered from an abstract perspective as items in a space of vectors all of which satisfy the rules of the “game” of vectors, as well as from a concrete perspective as lists of numbers upon which the operations of vectors are defined (addition and scaling).

Similarly, matrices can be considered from an abstract perspective as “linear operations” upon an abstract space of vectors, or from a concrete perspective as arrays of numbers which operate upon the lists of numbers in concrete vectors.

Link to original

Matrices acting on vectors

Matrices acting on vectors

An matrix is an array of numbers. Given a matrix called , the numbers making it up are called “coefficients” and written for and . Sometimes we write . The first index always specifies the row, and the second index specifies the column. For example, we could have:

center
Suppose we have a 2D vector and a 3D vector :

Now the action of on and of on can be written out with these formulas:

Link to original

Example

Matrix acting on a vector

Matrix acting on a vector

Link to original

Matrices acting on vectors (part 2)

Let be an matrix and let be an D vector. Using summation notation for large numbers of indices, the matrix times vector operation is given by the general formula for the row of the output vector, where :

Link to original

Question

01

Summation notation

Write out the formula for the operation of a matrix on a D vector. (Convert the summation notation to ordinary sums.)

Link to original

Matrices acting on vectors (part 3)

The formulas for the action of a matrix on a vector should be understood in two different ways.

  • For concrete calculations, it is best to think of each row of the output vector as the dot product of the corresponding matrix row with the input vector.
  • For conceptual and abstract understanding, it is better to think of the operation as sending each standard basis vector to the corresponding column vector of the matrix.

Let’s consider now the second way in more detail. A matrix can be considered as a list of column vectors. For example:

Then :

Recall the standard basis vectors are and . So:

Similarly, in general:

Link to original

Diagonal matrices: stretching

Diagonal matrices - stretching

The main diagonal of a matrix consists of the entries . A matrix is called diagonal when all entries are zero except on the main diagonal. The action of a diagonal matrix is to stretch each spatial dimension according to the corresponding diagonal number:

This action is very easy to express algebraically in terms of standard basis vectors:

In other words, standard basis vectors are sent to scalar multiples of themselves. This means that standard basis vectors are eigenvectors (“self-vectors”) for a diagonal matrix, and the diagonal numbers (the scalar multiples) are eigenvalues (“self-values”).

When the diagonal entries are all the same, the effect is to scale all of space by equal proportions:

In this case, when the transformation is called a dilation because vectors expand away from the origin, and when it is called a contraction because vectors shrink towards the origin.

Link to original

Question

02

Stretching and area

Consider the unit square . What is the area of the image of this square under the action of the matrix ?

Link to original

Shearing

Shearing

A simple shear mapping (also shear transformation or transvection) performs a displacement of one coordinate by a proportion of another. The matrix of a 2D shear in is given by:

center
Horizontal lines remain horizontal, while vertical lines take on a new slope of . Interestingly, shearing preserves area. (We will see a very simple explanation later.)

There is also shear in :

A shear in 3D might look like this:

The shear takes place in the component corresponding to the row of the matrix with .
There is a general definition of shear mapping in D space, but we do not use it.

Link to original

Rotating

Rotating

A rotation in 2D by the angle (counterclockwise) can be performed by a matrix:

Link to original

Exercise

01

Rotation matrix

Using geometry and trig sum identities, verify that this is the correct formula for rotation of the point counterclockwise about the origin by the angle .

Link to original

Rotating (part 2)

From the matrix for rotation by we can deduce that counterclockwise rotation by is given in matrix form by , which acts by , and clockwise rotation by is given in matrix form by , which acts by . Rotation by is given by , which acts by , and this is simply reflection through the origin.

Study of 3D rotations has myriad applications in science and engineering, but rotations in 3D are much more complicated than in 2D, and we do not investigate the theory very much here. Some basic rotations are given by simple 2D rotations in the separate pairs of coordinates:

These rotations are called yaw, pitch, and roll, respectively. (These terms apply to an airplane flying in the -plane in the axis direction.) Simple rotations like these in two chosen axes are also called Givens rotations (after J. Wallace Givens). They are easily generalized to D space.

Link to original

Question

03

Positive pitch

Verify from the formulas that a positive pitch means an airplane is ascending. Does a positive roll imply an airplane is tilting to the right or to the left?

Link to original

Projecting

Projecting

A projection matrix acts on vectors by sending them to the nearest point in some chosen linear subspace, for example on a line (in 2D space) or on a plane (in 3D space). The chosen subspace has lower dimension than all of space, and the image under projection is like a shadow of the original.

Consider the projection of to the direction of . Let us assume that is a unit vector; then the projection formula simplifies to:

We can express this formula using a matrix. In 2D we have:

and

The matrix actually has a name: it is called the outer product , where is the matrix . In more detail: is a row vector matrix which, when applied to any vector , gives the scalar quantity . This horizontal matrix can be embedded inside each row of the vector by multiplying by the component in that row of and substituting the result into the row, thereby converting the vector into a matrix. The action of this matrix on is first to take the dot product , and then to apply this scalar to each row of , in other words multiplying overall by this scalar.

In conclusion, the operation is a linear mapping, and it can be represented as the action of a matrix:

Now if is not a unit vector, this matrix is incorrect. The matrix can be corrected by multiplying every coefficient by , which is .

Link to original

Exercise

02

Computing a projection matrix

Find the matrix of the projection of in the direction of the vector . (First compute the unit vector.)

Link to original

Exercise

03

Double projections

Consider a unit vector and another vector . Show that . Do this by applying the matrix of the projection of to the vector twice in sequence (meaning you apply the matrix again on the output vector of the first application of the matrix). To simplify the result, remember that because is a unit vector.

Link to original

Projecting (part 2)

The same matrix formula can be extended to 3D and D. In 3D the matrix would be:

For a unit vector, this matrix acts on by giving , the projection to the direction of . We can see this because it clearly gives .

It is good to highlight the matrices of projection to the standard basis vectors:

Link to original

Question

04

Projection to standard basis

Check that sends and sends . What is the matrix of in 3D, for ?

Link to original

Reflecting

Reflecting

A reflection matrix is a matrix that acts on vectors by reflecting them across a hyperplane that passes through the origin. These operations are called Householder reflections.

(A hyperplane is a plane of one dimension lower than the surrounding space. So, a hyperplane in 2D is a line, and a hyperplane in 3D is a 2D plane. A hyperplane in D would be an D plane.)

The matrix of a reflection can be derived from the matrix of a certain projection by considering a formula for the reflection in terms of dot products.

If is any vector, the reflection of in the hyperplane through the origin, perpendicular to the vector is given by:

To see how the formula works, consider that is the component of perpendicular to , meaning that it lies in the hyperplane of reflection. Adding to recovers by bringing back the parallel part on the same side of the hyperplane as . Subtracting the term a second time does the opposite, it restores the part parallel to but on the other side of the hyperplane.

Reasoning via the hyperplane is not strictly necessary in 2D, but the same reasoning also works in D. In 3D the same formula gives the reflection across the plane through the origin, perpendicular to the vector . Here, gives the component of coming out of this plane in along . Subtracting once gives a vector inside the plane; subtracting twice gives the mirror image vector on the opposite side of the plane.

A 2D reflection in the hyperplane perpendicular to can be represented as the action of a matrix:

The action of this matrix sends a vector to the vector . (Check this fact yourself!)

Link to original

Exercise

04

Computing a reflection matrix

Compute the matrix representing 3D reflection in the plane perpendicular to the vector . (First find the unit vector!)

Link to original

Permuting

Permuting

A permutation is a way of reassigning some labels to a collection of items. For example, if some marbles numbered are placed (out of order) in bins numbered , then a permutation corresponds to withdrawing the marbles and placing them in the same bins but in a new order.

A permutation matrix is a matrix in which each column and each row has a single , and all other entries are . For example:

The action of a permutation matrix on a vector is simply to permute the rows of the vector:

Such a matrix acts by permuting rows because each row, with its single entry of , “picks out” the entry of the vector whose row corresponds to the column of this (all others are given times ); and since each column of the matrix has only a single , each row of the vector is “picked out” only one time.

The action of a permutation matrix on standard basis vectors is easy to describe: it permutes them.

Link to original

Exercise

05

Finding a permutation matrix

Find the permutation matrix that acts as follows:

Link to original

Tutorial: Theory of Matrices in 2D and 3D

Matrix multiplication

Matrix multiplication

Suppose we have a matrix and a vector that acts upon. We have written “” for the output vector given by letting act on .

Matrices act by sending vectors to other vectors. It is useful to consider another matrix that acts upon the output vector. For example, if , and if is a matrix that acts upon , we can write . (The colon in means “ is defined as .”)

Suppose we define , so that . Then we say that is the output of under a composition of actions of the matrices and . It turns out that if we start with two matrices and , the composition action (letting the matrices act consecutively) can itself be represented by a single matrix. (The composition of linear transformations is a linear transformation.) Let us find this matrix in the case when and are matrices.

Suppose the entries of and are given by

Now compute the action of followed by the action of on the vector :

Therefore, we define the product matrix by this formula:

With this definition and the above reasoning, we have that .
(Because of this equality, we can omit the parentheses and write simply , since the result is the same whether you act first by and then by or instead you first multiply the matrices and then act by .)

Just as for the formula for a matrix acting on a vector, we have multiple ways to interpret the formula for the matrix .

  • Each entry of the product matrix is given by taking the dot product of a row of with a column of .
  • Each column of the product matrix is given by letting act upon the corresponding column vector of . In other words, . (Recall that the action of upon has two interpretations of its own!)
  • Each row of the product matrix is given by letting the entries in the corresponding row vector of provide the coefficients for a linear combination of the rows of .
    The first of these interpretations is best for doing calculations, and the second is best for understanding abstract theory.

Bottom-Right Method for computing :
center
E.g.:
center

Max Born, Nobel Prize lecture:
center

Link to original

Question

01

Some matrix products

Compute the following matrix products by hand:

  • (a)
  • (b)

In both (a) and (b) there are three matrices: two are given and their product is the third. In (a), what size vectors do these three matrices act upon? (How many components?) In (b), what do you notice about the nature of the two matrices and their resulting product? Can you guess a rule that generalizes this fact?

Link to original

Question

02

Double rotation

Show that , in other words two rotations by is equivalent to one rotation by .

Link to original

Exercise

01

Nilpotent matrix

Define the matrix :

For , calculate the powers , , , , .

(What special property does have? A matrix with that property is said to be nilpotent.)

Link to original

Matrix multiplication (part 2)

Identity matrix
Notice that the diagonal matrix with ’s on the diagonal acts upon another vector or matrix by doing nothing:

This matrix is called the identity matrix, since it preserves the identity of whatever it acts upon. It is frequently written “”, regardless of the size of the matrix. So for any .

Sometimes is written more specifically as , where is the number of rows or columns. (Identity matrices always have the same number of rows and columns.)

Link to original

Exercise

02

Reflections square to identity

Show that for any with .

This means that reflecting twice across the same line gives back the original vector. (In 2D the hyperplane of reflection is just a line.)

Link to original

Matrices acting on matrices

Matrices acting on matrices

It is useful to think of matrices as acting upon other matrices by multiplying on the left. The effect is the same as the effect of acting on a vector, but it performs this (same) action on each column vector separately. The action is therefore the same across any given row.

Diagonal matrices
When two diagonal matrices are multiplied, the result is a diagonal matrix. The diagonal entries of the product are simply the products of the diagonal entries:

A consequence is that diagonal matrices commute with each other: when are both diagonal. (As seen with 3D rotations, frequently this is not true for matrix multiplication.)

Row-scale matrices
The diagonal matrices

have the effect of scaling rows (respectively) by the number , without changing other rows, when they are multiplied on a vector or a matrix on the left. These matrices are called row-scale matrices.

Permutation matrices
When two permutation matrices are multiplied, the result is a permutation matrix. For example:

Link to original

Question

03

Permutation matrices

Explain why the product of two permutation matrices is always a permutation matrix. (Recall the definition: a matrix is a permutation matrix when each row and each column contains exactly one and the other entries are .)

Link to original

Matrices acting on matrices (part 2)

Row-swap matrices
A permutation matrix acts upon another matrix (multiplying on the left) by permuting the rows of the matrix, in the same way that it would permute the rows of a vector:

The most important permutation type is one which simply swaps two rows and leaves the others unchanged. This type of matrix is called a row-swap matrix.

The row-swap action is performed by a permutation matrix which has ’s on the diagonal except for two rows. In these two rows, the ones from a diagonal matrix are swapped with each other.

Link to original

Example

Row-swap example

Row-swap example

The matrix which swaps rows and (of a vector or another matrix) works like this:

To obtain this row-swap matrix, start with the diagonal matrix with ’s along the diagonal, and then swap rows and .

Link to original

Matrices acting on matrices (part 3)

Row-add matrices
A matrix that has ’s on the diagonal and the other entries ’s, except for a single additional entry , is called an elementary shear matrix, or a row-add matrix:

If the entry is in the row and column, this matrix acts by taking the row (of a matrix or vector that it’s acting upon) and adding it into the row with a coefficient:

Remember that when a matrix is multiplied on the left on a vector or a matrix, the top row of the matrix controls the top row of the output.

Link to original

Matrix algebra

Matrix algebra

Matrix addition and scaling
Matrices can be added, subtracted, and multiplied by scalers, just like vectors. These operations are done componentwise:

In terms of the actions performed by these matrices, addition is like addition of functions: the action of a sum of matrices is to give the sum of the outputs under the actions of the separate matrices. For functions, this would be written . For matrices, we write , and similarly for subtraction, scalar multiples, and other variations on basic algebra operations.

Matrix distributivity
It is important to notice that matrix multiplication is compatible with matrix addition in the usual sense of distributivity:

One way to prove this formula is to show that it is true after both sides are applied to an arbitrary vector . (To complete the proof, let take the specific value of each standard basis vector in turn, and you find that column of the matrices on each side must agree.) To show the equality after multiplying both sides on an arbitrary , we need to check distributivity of matrix actions on vectors in general:

Link to original

Question

04

Linearity / Distributivity of matrix actions

Show that whenever a matrix acts on vectors and .

Hint: first try this with a matrix and 3D vector with arbitrary entries. Then to show it in general, use the “summation notation” for the matrix action on a vector:

Link to original

Matrix algebra (part 2)

Matrix division
For real numbers, division and multiplication are inverse processes, meaning that division “undoes” the action of multiplication, and vice versa.

Any number can divide another number provided it is not zero. For matrices, the situation is more complex, because “being zero” is more complex. Many matrices have non-zero entries, yet they “act as zero” upon certain other vectors. When this happens, the action cannot be “undone”, because you cannot divide by the zero action performed on those vectors.

Link to original

Example

Projection is not invertible

Projection is not invertible

Consider the projection matrix which sends a vector to the vector . This matrix acts by zero upon any vector , sending to . This action cannot be undone! (What specific vector would the inverse action send to?)

Link to original

Matrix algebra (part 3)

So, some matrices can be divisors. These are called invertible matrices. Others cannot, and these are called non-invertible matrices. A matrix is invertible when the inverse matrix exists.

When it exists, an inverse matrix acts by undoing multiplication by . Concretely, this means:

Notice in the second formula that the action of can be undone before even acts. (Ordinary division also works like this!) Another way to look at it is that acts by undoing the effect of . (Ordinary division: multiplication by undoes the effect of multiplying by .)

Recall the “identity matrix” which satisfies for any . So we can write the above formula using matrices:

Notice that we have to write both formulas because matrix multiplication is not commutative! (Ordinary division: and are equivalent because for any numbers.)

Inverse of matrices
There is a general formula for the inverse of any matrix that should be memorized:

Link to original

Exercise

03

Checking formula for inverse

Check the formula for for a matrix by computing by hand and . (You should obtain in both cases.)

Which matrices have an inverse?

(Hint: you just checked a formula that works whenever it makes sense, so there is an inverse whenever it makes sense, given by the formula. Suppose are such that the formula does not make sense. Can you find a vector which is sent to by ?)

Link to original

Exercise

04

Inverse of a reflection

Show (in 2D) that the matrix of a reflection is the inverse of itself. Show this first abstractly (using the definition of inverse), and then concretely (using the formulas for reflection and inverse matrices).

Link to original

Exercise

05

Inverse of a rotation

Show (in 2D) that the inverse of the matrix of rotation by is the matrix of rotation by .

Link to original

Matrix algebra (part 4)

The inverse of is useful for finding a vector which is sent to a given vector by the action of a given matrix :

If we know and , and we want , this method will give us .

Link to original

Example

Inverse matrix to find preimage

Inverse matrix to find preimage

Problem: Define

Find a vector with the property that , meaning that sends to the given .

Solution: First we compute using the formula. We have , so . Now compute that , and this is our answer for . Check this answer by computing , as expected.

Link to original

Exercise

06

Inverse matrix to find preimage

Repeat the previous example for this data:

Link to original

Matrix algebra (part 5)

Determinant of matrices
The determinant of a matrix , written , is a single number that is associated to the matrix.

For a matrix, the determinant is given by the formula in the divisor of the formula for :

We will learn many things about determinants. The important thing for now is that exists if and only if .

Optional: interpretation of determinant
Just for fun, here is a visual proof (by S. Golomb) that gives the area of the parallelogram spanned by the column vectors of , namely and :
center
Here is another visual for parallelograms from obtuse vectors:
center

Link to original

Eigenvectors, eigenvalues

Eigenvectors, eigenvalues

We saw that standard basis vectors are eigenvectors for diagonal matrices, and the diagonal entries are the eigenvalues. If has diagonal entries , then .

Now consider the problem of finding eigenvectors and eigenvalues for a non-diagonal matrix . This means finding a vector and a scalar such that .

Suppose we start with a hypothetical . Write for the matrix . So we wish to solve , which is equivalent to . Now write . So we wish to find such that .

Notice that if is invertible, then there is no solution. (The only solution would be and that is not allowed for an eigenvector.) The reason is that if exists, we can let it act upon both sides of the equation to obtain . Therefore, we only have a chance of solving this if is non-invertible. Recall from above that is non-invertible precisely when .

It turns out we can solve the equation if . Let us do this by hand for matrices.

Derivation that if then can be solved with

Let . Assume , which means or or . Write for the common ratio . Thus , and now we wish to solve the equation:

This means and . Dividing the latter by we arrive at the former, so we can take any that satisfy . Let us choose . You can now check directly that it works:

If , there must be a vector such that for some scalar

Proof: Define , and so

Suppose . By the formula for , this means . That is a quadratic equation in and could be rewritten as . By the quadratic formula, the solutions are . Write these two solutions as and .

So we have found and with and . In either case we can solve for a such that and a such that using the method in the box above.

Link to original

Example

Finding eigenvectors and eigenvalues

Finding eigenvectors and eigenvalues

Problem: Define . Find the two eigenvalues and some (any) two corresponding eigenvectors of .

Solution: First write . Then means . Solve this quadratic equation to obtain and . We have found the two eigenvalues.

Next, write out the matrices

Our goal is to find and such that . We can guess two solutions: let and let . To check that these are indeed eigenvectors of the original corresponding to and , compute:

You could also use the procedure in the gray box “Derivation.” For we have , and for we have . Then we would get and . Notice that the first eigenvector is a scalar multiple of ours above: .

This is true in general: if , then . In other words, you can scale an eigenvector and the result is still an eigenvector with the same eigenvalue. This is because when is a scalar, and of course when both are scalars. In yet other words, the line spanned by an eigenvector , called an eigenline, is preserved by the matrix: every vector on this line is mapped back to something on this line.

Link to original

Summary

Summary

  • Matrices can be multiplied by each other. Express as a row of column vectors; then is the matrix which is the row of column vectors . In other words, is computed by letting act upon the columns of .
  • Matrices acting on vectors satisfy , and acting on matrices they satisfy .
  • The identity matrix has the property that and for any other matrix .
  • Row-scale matrices act on a matrix (or vector) by scaling a chosen row. Row-swap matrices act by swapping two rows. Row-add matrices act by adding one row into another.
  • An “invertible” matrix is one having an inverse , which has the property that . (Here is an matrix.) For a matrix, its inverse is given by a formula:
  • The inverse matrix can be used to solve for in the equation , where and are both given and is sought.
  • The determinant for the matrix (as above) is the number . The matrix is invertible if and only if .
  • Given the matrix , an eigenvector is a vector () such that for some scalar called the eigenvalue corresponding to .
  • We can find eigenvalues and eigenvectors by: setting and solving a quadratic equation to find , , then plugging these in for and writing and , and then manually solving for vectors and satisfying and . This is possible using the fact that one row of will be a multiple times the other row.
Link to original