Packet 03

Tutorial: Inventory of Matrices in 2D and 3D

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.

Matrices acting on vectors

An n×m matrix is an n×m array of numbers. Given a matrix called A, the numbers making it up are called “coefficients” and written aij for i=1,,n and j=1,,m. Sometimes we write A=(aij). The first index always specifies the row, and the second index specifies the column. For example, we could have:

A=(a11a12a21a22)orB=(b11b12b13b21b22b23b31b32b33).

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

𝐮=(u1u2)and(v1v2v3).

Now the action of A on 𝐮 and of B on 𝐯 can be written out with these formulas:

A𝐮=(a11a12a21a22)(u1u2)=(a11u1+a12u2a21u1+a22u2), B𝐯=(b11b12b13b21b22b23b31b32b33)(v1v2v3)=(b11v1+b12v2+b13v3b21v1+b22v2+b23v3b31v1+b32v2+b33v3).

Example

Matrix acting on a vector

(1421)(36)=(13+4623+16)=(2712)

Let C be an n×m matrix and let 𝐰 be an mD vector. Using summation notation for large numbers of indices, the matrix times vector operation is given by the general formula for the ith row of the output vector, where i=1,,n:

(C𝐰)i=j=1mCijwj.
Question 03-01

Summation notation

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

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:

A=(a11a12a21a22)=(𝐚1𝐚2), with 𝐚1=(a11a21),𝐚2=(a12a22).

Then A𝐮=u1𝐚1+u2𝐚2:

(𝐚1𝐚2)(u1u2)=u1(a11a21)+u2(a12a22).

Recall the standard basis vectors are 𝐞1=(10) and 𝐞2=(01). So:

A𝐞1=(a11a21),A𝐞2=(a12a22).

Similarly, in general:

C𝐞i=𝐜i=(c1ic2icni).

Diagonal matrices: stretching

The main diagonal of a matrix A=(aij) consists of the entries a11,a22,,ann. 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:

(a1000a2000a3)(xyz)=(a1xa2ya3z).

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

A𝐞1=a1𝐞1,A𝐞2=a2𝐞2,A𝐞3=a3𝐞3.

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:

(a000a000a)(xyz)=(axayaz)=a(xyz).

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

Question 03-02

Stretching and area

Consider the unit square [0,1]×[0,1]. What is the area of the image of this square under the action of the matrix (a100a2)?

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 x is given by:

(1m01)(xy)=(x+myy).

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

There is also shear in y:

(10m1)(xy)=(xy+mx).

A shear in 3D might look like this:

(10001m001)(xyz)=(xy+mzz).

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

Rotating

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

(cosθsinθsinθcosθ)(xy)=(xcosθysinθxsinθ+ycosθ).
Exercise 03-01

Rotation matrix

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

From the matrix for rotation by θ we can deduce that counterclockwise rotation by 90 is given in matrix form by (0110), which acts by (x,y)(y,x), and clockwise rotation by 90 is given in matrix form by (0110), which acts by (x,y)(y,x). Rotation by 180 is given by (1001), which acts by (x,y)(x,y), 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:

Rxy(θ)=(cosθsinθ0sinθcosθ0001),Rxz(θ)=(cosθ0sinθ010sinθ0cosθ),Ryz(θ)=(1000cosθsinθ0sinθcosθ)

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

Question 03-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?

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:

proj𝐯(𝐮)=𝐯(𝐯𝐮).

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

(𝐯𝐮)=(v1v2)(u1u2)=v1u1+v2u2,

and

𝐯(𝐯𝐮)=(v1(𝐯𝐮)v2(𝐯𝐮))=(v1(v1u1+v2u2)v2(v1u1+v2u2))=(v1v1u1+v1v2u2v2v1u1+v2v2u2)=(v1v1v1v2v2v1v2v2)(u1u2).

The matrix (v1v1v1v2v2v1v2v2) actually has a name: it is called the outer product 𝐯𝐯, where 𝐯 is the matrix (v1v2). In more detail: 𝐯 is a 1×2 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 proj𝐯() is a linear mapping, and it can be represented as the action of a matrix:

[proj𝐯]=(v1v1v1v2v2v1v2v2).

Now if 𝐯 is not a unit vector, this matrix is incorrect. The matrix can be corrected by multiplying every coefficient by (𝐯𝐯)1, which is 1/(v1v1+v2v2).

Exercise 03-02

Computing a projection matrix

Find the matrix of the projection of 2 in the direction of the vector 𝐯=(3,4). (First compute the unit vector.)

Exercise 03-03

Double projections

Consider a unit vector 𝐯 and another vector 𝐮. Show that proj𝐯(proj𝐯(𝐮))=proj𝐯(𝐮). 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 𝐯𝐯=1 because 𝐯 is a unit vector.

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

(v1v2v3)(v1v2v3)=(v1v1v1v2v1v3v2v1v2v2v2v3v3v1v3v2v3v3).

For 𝐯 a unit vector, this matrix acts on 𝐮 by giving proj𝐯(𝐮), 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:

[proj𝐞1]=(1000),[proj𝐞2]=(0001).
Question 03-04

Projection to standard basis

Check that proj𝐞1 sends (x,y)(x,0) and proj𝐞2 sends (x,y)(0,y). What is the matrix of proj𝐞i in 3D, for i=1,2,3?

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 nD would be an (n1)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:

refl𝐯(𝐮)=𝐮2proj𝐯(𝐮).

To see how the formula works, consider that 𝐮proj𝐯(𝐮)=𝐮 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 nD. In 3D the same formula gives the reflection across the plane through the origin, perpendicular to the vector 𝐯. Here, proj𝐯(𝐮) 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:

[refl𝐯]=(1001)2[proj𝐯]=(1001)2(v1v1v1v2v2v1v2v2)=(12v1v12v1v22v2v112v2v2).

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

Exercise 03-04

Computing a reflection matrix

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

Permuting

A permutation is a way of reassigning some labels to a collection of items. For example, if some marbles numbered 1,,n are placed (out of order) in bins numbered 1,,n, 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 1, and all other entries are 0. For example:

(0110),(010100001),(0001100000100100).

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

(0110)(v1v2)=(v2v1),(010100001)(v1v2v3)=(v2v1v3), (0001100000100100)(v1v2v3v4)=(v4v1v3v2).

Such a matrix acts by permuting rows because each row, with its single entry of 1, “picks out” the entry of the vector whose row corresponds to the column of this 1 (all others are given times 0); and since each column of the matrix has only a single 1, 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.

Exercise 03-05

Finding a permutation matrix

Find the permutation matrix that acts as follows:

(a2a4a1a5a3)(a1a2a3a4a5).

Problems due Monday 5 Feb 2024 by 12:00pm

Problem 03-01

Composing rotations

Write the matrix of rotation by θ and the matrix of rotation by φ. Now apply the first matrix to (x,y) and the second matrix to the output of (x,y) under the action of the first matrix. Show that the resulting vector is the same as the vector given by applying a single rotation by the angle θ+φ. (You will need trig identities.)

Problem 03-02

Yaw and pitch do not commute

In this problem you will show that 3D rotations do not commute, meaning that the outcome of two rotations can be affected by the order in which the rotations are performed.

Write an arbitrary vector symbolically as (v1v2v3). Rotate this vector by a yaw of +90 using the yaw rotation matrix, and then rotate the output by a pitch of +90. Now do this in reverse: a pitch rotation of +90 followed by a yaw rotation of +90. Show that the results do not agree! Can you visualize this by rotating your hand?

Problem 03-03

Finding matrices

  • (a) Find a 3×3 matrix that acts as follows:
(v1v2v3)(3v12v34v1v1v2+v3).
  • (b) Find a 3×2 matrix that acts as follows:
(v1v2)(v1v22v1+v2v1).
  • (c) Find a 4×4 matrix that acts as follows:
(v1v2v3v4)(v1+v2v2+v3v3+v40).
  • (d) Find the matrix of a horizontal shear that maps 𝐞2 to 𝐞2+3𝐞1 and does not change 𝐞1.
Problem 03-04

Rotations via reflections

Given an angle θ for a counterclockwise rotation of the xy-plane, find two lines such that reflecting in these two lines in sequence performs the rotation by θ.

(This means that any rotation in the xy-plane can be accomplished by performing two reflections in sequence!)

Hint: try picking a very simple line as your first reflection line, e.g. an axis, and a more interesting line as your second reflection line.

You may find it convenient to consider that the formula

(12v1v12v1v22v2v112v2v2)

for a reflection matrix is satisfied by the matrix

(cos2θsin2θsin2θcos2θ).

(Expand the entries using double-angle formulas to see why!) This matrix gives the reflection through the line which meets the x-axis at the origin at an angle of θ.