Homework 5: Matrices

due Sunday, October 18th, 2026 at 11:59PM Ann Arbor Time
(Homeworks are now due on Sundays!)

Except for the video link in Problem 1, write your solutions to the following problems either by writing them on a piece of paper or on a tablet and scanning your answers as a PDF. Note that you are not allowed to use LaTeX, Google Docs, or any other digital document creation software to type your answers. Homeworks are due to Pensive by 11:59PM on the due date. See the syllabus for details on the slip day policy.

Homework will be evaluated not only on the correctness of your answers, but on your ability to present your ideas clearly and logically. You should always explain and justify your conclusions, using sound reasoning. Your goal should be to convince the reader of your assertions. If a question does not require explanation, it will be explicitly stated.

Before proceeding, make sure you’re familiar with the collaboration policy.


Problems


Total Points: 5 + 12 + 15 + 10 + 20 + 20 + 10 + 8 = 100


Note: You may find it helpful to check some of your answers using numpy, once you’ve already done the calculations by hand. This video gives you tips on using numpy for various matrix calculations. It’s important to learn how to do both – doing calculations by hand, so you know how they actually work, and using code to perform computation efficiently.


Problem 1: Midterm 1 Video Reflection (5 pts)

Instead of asking you to write a reflection, you’ll need to record a video !

Review the solutions to Midterm 1. Pick one question or problem part that you answered incorrectly, but now understand after reviewing the solutions and reflecting on your work.

Record a 2- to 5-minute video explaining that question. Tell us what the question asks, what you got wrong or misunderstood, and how to solve it now. Explain the reasoning in your own words; don’t just read the posted solution aloud.

The video should be just you speaking into the camera. Your face must be visible while you are talking for the entire video. Do not include slides, a screen recording, written work, or any other visuals.

Submit your video link to the separate assignment on Pensive called Homework 5, Problem 1 Video Link. You can upload your video to YouTube as unlisted, share a Zoom recording link, or share a Google Drive link; whatever works. Make sure the course staff can view the video using that link.

Your submission time for Homework 5 is the later of the two submission times: your Problem 1 video link and your regular Homework 5 PDF.

This problem is graded on completion. Record a video of the required length and make an honest effort to explain the question, and you will receive full credit. Your explanation does not need to be polished or perfect.


Problem 2: Projecting onto a Plane (12 pts)

In Lecture 11, we stated our eventual goal: projecting \(\vec u\) onto \(\operatorname{span}(\lbrace\vec v_1,\ldots,\vec v_d\rbrace)\). We already have enough information for a special case: projecting onto a plane through the origin in \(\mathbb R^3\).

Let

$$ \vec v_1=\begin{bmatrix}2\\\\3\\\\-1\end{bmatrix},\qquad \vec v_2=\begin{bmatrix}3\\\\4\\\\-2\end{bmatrix},\qquad \vec u=\begin{bmatrix}4\\\\1\\\\0\end{bmatrix} $$

Let \(S=\operatorname{span}(\lbrace\vec v_1,\vec v_2\rbrace)\).

Figure from the assignment PDF

a)

(4 pts) Find a nonzero vector \(\vec n\) orthogonal to both \(\vec v_1\) and \(\vec v_2\), and use it to find an equation for the plane \(S\) of the form \(ax+by+cz=0\).

Solution

Let’s write \(\vec n=\begin{bmatrix}a\\b\\c\end{bmatrix}\). For \(\vec n\) to be orthogonal to both vectors, we need

$$ 2a+3b-c=0,\qquad 3a+4b-2c=0. $$

The first equation gives \(c=2a+3b\). Substituting into the second gives \(a=-2b\), and then \(c=-b\). Choosing \(b=1\) gives

$$ \boxed{\vec n=\begin{bmatrix}-2\\\\1\\\\-1\end{bmatrix}},\qquad \boxed{-2x+y-z=0}. $$

Since \(\vec v_1\) and \(\vec v_2\) aren’t scalar multiples, their span is a plane. Both are orthogonal to \(\vec n\), so this is exactly the plane \(S\).

b)

(3 pts) Find \(\vec q\), the projection of \(\vec u\) onto \(\vec n\). Then compute \(\vec p=\vec u-\vec q\).

Solution

Using the projection formula,

$$ \vec q=\frac{\vec u\cdot\vec n}{\vec n\cdot\vec n}\vec n =\frac{-7}{6}\begin{bmatrix}-2\\\\1\\\\-1\end{bmatrix} =\boxed{\begin{bmatrix}7/3\\\\-7/6\\\\7/6\end{bmatrix}}. $$

So,

$$ \vec p=\vec u-\vec q=\begin{bmatrix}4\\\\1\\\\0\end{bmatrix}-\begin{bmatrix}7/3\\\\-7/6\\\\7/6\end{bmatrix}=\boxed{\begin{bmatrix}5/3\\\\13/6\\\\-7/6\end{bmatrix}}. $$
c)

(5 pts)

  1. Verify that \(\vec p\) is on the plane from part a).

  2. Write \(\vec p\) as a linear combination of \(\vec v_1\) and \(\vec v_2\).

  3. Explain why \(\vec p\) is the projection of \(\vec u\) onto \(S\).

Solution

(i) Substituting the components of \(\vec p\) into our plane equation gives

$$ -2\left(\frac53\right)+\frac{13}{6}-\left(-\frac76\right)=0, $$

so \(\vec p\) is on the plane.

(ii) To write \(\vec p=a\vec v_1+b\vec v_2\), we need

$$ 2a+3b=\frac53,\qquad 3a+4b=\frac{13}{6},\qquad -a-2b=-\frac76. $$

The first two equations give \(b=\frac23\) and \(a=-\frac16\), which also satisfy the third. So,

$$ \boxed{\vec p=-\frac16\vec v_1+\frac23\vec v_2}. $$

(iii) We know that \(\vec p\) is in \(S\), and \(\vec u-\vec p=\vec q\) is a multiple of \(\vec n\), so it’s perpendicular to \(S\). These are exactly the two properties we need: the projection lies on the plane, and the leftover vector is perpendicular to it.


Problem 3: Getting Started with Matrices (15 pts)

Let

$$ A = \begin{bmatrix} 3 & 0 & 4 \\\\ 0 & 1 & 0 \\\\ 2 & -1 & -3 \\\\ 5 & 0 & -1 \\\\ 3 & 2 & 0 \end{bmatrix} $$
a)

(4 pts) In each subpart, state whether the resulting object is a matrix, vector, or scalar. If the result is a matrix or vector, state its dimensions. If the result is not defined, state why. You don't need to actually compute the resulting objects.

  1. \(A^T\)

  2. \(A^TA\)

  3. \(AA^T\)

  4. \(A^TA + AA^T\)

  5. \(A^T \vec x\), where \(\vec x \in \mathbb{R}^3\)

  6. \(A^T \vec x\), where \(\vec x \in \mathbb{R}^5\)

  7. \(\vec x^T A^T A \vec x\), where \(\vec x \in \mathbb{R}^3\)

Solution

Since \(A\) has shape \(5\times3\), we get:

  1. A matrix with shape \(3\times5\). Transposing swaps rows and columns.

  2. A matrix with shape \(3\times3\), since \((3\times5)(5\times3)\) gives \(3\times3\).

  3. A matrix with shape \(5\times5\), since \((5\times3)(3\times5)\) gives \(5\times5\).

  4. Undefined: we can’t add matrices with different shapes.

  5. Undefined: the inner dimensions in \((3\times5)(3\times1)\) don’t match.

  6. A vector in \(\mathbb R^3\), since \((3\times5)(5\times1)\) gives \(3\times1\).

  7. A scalar. We can write this as \((A\vec x)^T(A\vec x)\), the dot product of \(A\vec x\) with itself.

b)

(3 pts) Evaluate \(A\begin{bmatrix} 3 \\ 0 \\ -2 \end{bmatrix}\).

There are two interpretations of the resulting vector, based on what we’ve seen in Chapter 5.1 — what are they?

Solution

Multiplying each row of \(A\) by the vector gives

$$ A\begin{bmatrix}3\\\\0\\\\-2\end{bmatrix} =\begin{bmatrix}9-8\\\\0\\\\6+6\\\\15+2\\\\9\end{bmatrix} =\boxed{\begin{bmatrix}1\\\\0\\\\12\\\\17\\\\9\end{bmatrix}}. $$

There are two ways to read this calculation. Each component is the dot product of a row of \(A\) with the input vector. Alternatively, the entire result is a linear combination of the columns of \(A\): 3 times the first column, plus 0 times the second, minus 2 times the third.

c)

(5 pts) In both subparts, try and find a vector \(\vec x \in \mathbb{R}^3\) such that \(A \vec x = \vec b\). If it’s not possible to do so, explain why.

  1. \(\vec b = \begin{bmatrix} 0 \\ 5 \\ 3 \\ -1 \\ 4 \end{bmatrix}\)

  2. \(\vec b = \begin{bmatrix} 10 \\ 1 \\ -17 \\ -14 \\ -4 \end{bmatrix}\)

Solution
  1. There is no solution. The second row gives \(x_2=5\), and the fifth row then gives \(3x_1+10=4\), so \(x_1=-2\). But the first row requires \(-6+4x_3=0\), or \(x_3=\frac32\), while the fourth requires \(-10-x_3=-1\), or \(x_3=-9\). We can’t satisfy both, so \(\vec b\) isn’t in the column space of \(A\).

  2. The second row gives \(x_2=1\), and the fifth gives \(3x_1+2=-4\), so \(x_1=-2\). The first row then gives \(-6+4x_3=10\), so \(x_3=4\). We still need to check the other rows:

    $$ 2(-2)-1-3(4)=-17,\qquad 5(-2)-4=-14. $$

    Both work! So \(\boxed{\vec x=\begin{bmatrix}-2\\1\\4\end{bmatrix}}\) satisfies \(A\vec x=\vec b\).

d)

(3 pts) Explain why it’s the case that — for this particular matrix \(A\) — if \(A \vec x_1 = \vec b\) and \(A \vec x_2 = \vec b\), then \(\vec x_1 = \vec x_2\).

Solution

The key is that the columns of \(A\) are linearly independent. Let’s verify this: if \(A\vec z=\vec0\), row 2 gives \(z_2=0\), row 5 then gives \(z_1=0\), and row 1 gives \(z_3=0\). So the only solution is \(\vec z=\vec0\).

Now, if \(A\vec x_1=\vec b\) and \(A\vec x_2=\vec b\), subtracting gives

$$ A(\vec x_1-\vec x_2)=\vec0. $$

By what we just showed, \(\vec x_1-\vec x_2=\vec0\), so \(\boxed{\vec x_1=\vec x_2}\). In other words, a vector can be written as a linear combination of linearly independent vectors in only one way.


Problem 4: Correlation, Revisited (10 pts)

In this problem, we’ll see how the correlation coefficient between two variables, \(r\), can be expressed as a matrix multiplication.

Consider a dataset of \(n\) points, \((x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)\), and let

$$ D = \begin{bmatrix} x_1 - \bar{x} & y_1 - \bar{y} \\\\ x_2 - \bar{x} & y_2 - \bar{y} \\\\ \vdots & \vdots \\\\ x_n - \bar{x} & y_n - \bar{y} \end{bmatrix} $$

where \(\bar{x}\) and \(\bar{y}\) are the means of \(x\) and \(y\), respectively. Note that \(D\) is an \(n \times 2\) matrix, and it is mean-centered, meaning that the mean of each column is 0.

Define the matrix \(\Sigma\) as follows.

$$ \Sigma = \frac{1}{n} D^TD $$

\(\Sigma\) is a \(2 \times 2\) matrix. Its name is pronounced “sigma”, just like in summation notation and standard deviation. Don’t confuse it with summation notation; \(\Sigma\) is just a single matrix.

a)

(4 pts) For this particular matrix \(D\), find \(\Sigma\). All four components of \(\Sigma\) should be expressions involving the points \(x_1, x_2, \ldots, x_n\) and/or \(y_1, y_2, \ldots, y_n\). Feel free to use summation notation in your answers.

Solution

Each entry of \(D^TD\) is a dot product of two columns of \(D\). So,

$$ \boxed{\Sigma=\frac1n\begin{bmatrix} \sum_{i=1}^n(x_i-\bar x)^2 & \sum_{i=1}^n(x_i-\bar x)(y_i-\bar y)\\\\ \sum_{i=1}^n(x_i-\bar x)(y_i-\bar y) & \sum_{i=1}^n(y_i-\bar y)^2 \end{bmatrix}}. $$

Notice that the two off-diagonal entries are the same: swapping the order of a dot product doesn’t change its value.

b)

(2 pts) In English, what do the two elements on the diagonal (top-left and bottom-right) of \(\Sigma\) represent?

Solution

The top-left entry is the variance of \(x\), \(\sigma_x^2\), and the bottom-right entry is the variance of \(y\), \(\sigma_y^2\).

c)

(2 pts) You should notice that \(\Sigma\) is a symmetric matrix, meaning \(\Sigma^T = \Sigma\). (See Chapter 5.2 for more on symmetric matrices.) The elements off the diagonal (top-right and bottom-left) are both equal, and are called the covariance of \(x\) and \(y\). For that reason, \(\Sigma\) is often called the covariance matrix.

Find an expression for the off-diagonal elements of \(\Sigma\) in terms of the correlation coefficient, \(r\), \(\sigma_x\), and \(\sigma_y\), but with no summation notation or other variables.

Hint: This only requires 1-2 lines of work. Remember the definition of \(r\) from Chapter 2.4.

Solution

Recall that

$$ r=\frac{1}{n\sigma_x\sigma_y}\sum_{i=1}^n(x_i-\bar x)(y_i-\bar y). $$

Multiplying both sides by \(\sigma_x\sigma_y\) tells us that each off-diagonal entry is \(\boxed{r\sigma_x\sigma_y}\).

d)

(2 pts) In general, suppose \(X \in \mathbb{R}^{n \times d}\) is a matrix containing \(n\) observations for each of \(d\) variables/features. The covariance matrix of \(X\) is defined similarly.

$$ \Sigma = \frac{1}{n} X^TX $$

In English, explain what the element in row 3 and column 5 of this \(\Sigma\) represents.

Solution

Assuming each column of \(X\) has been mean-centered, this entry is the covariance between features 3 and 5. It’s their correlation multiplied by their two standard deviations.

The mean-centering assumption matters here, just as it did for \(D\). Without it, the entry is the average of the products of the two features, \(\frac1n\sum_{i=1}^n X_{i3}X_{i5}\); we’d need to subtract the product of their means to get the covariance.


Problem 5: Projections, Revisited (20 pts)

As we first saw in Chapter 3.4, the projection of \(\vec u\) onto \(\vec v\) is the vector \(\displaystyle \vec p = \left( \frac{\vec u \cdot \vec v}{\vec v \cdot \vec v} \right) \vec v\).

If we assume that \(\vec v\) is a unit vector, meaning \(\lVert \vec v \rVert = 1\), then the projection of \(\vec u\) onto \(\vec v\) has a simpler form,

$$ \vec p = (\vec u \cdot \vec v) \vec v $$

Assume that \(\vec u = \begin{bmatrix} u_1 \\ u_2 \end{bmatrix}\) is some arbitrary (not-necessarily unit) vector in \(\mathbb{R}^2\), and \(\vec v = \begin{bmatrix} v_1 \\ v_2 \end{bmatrix}\) is a unit vector in \(\mathbb{R}^2\).

a)

(4 pts) Find a \(2 \times 2\) matrix \(P\), called a projection matrix, such that

$$ P \vec u = \vec p = (\vec u \cdot \vec v) \vec v $$

Think of \(P\) as a matrix that transforms \(\vec u\) into an approximation of it, in the direction of \(\vec v\) (or “projects” \(\vec u\) onto \(\vec v\)).

Hint: Start by writing \(P = \begin{bmatrix} a & b \\ c & d \end{bmatrix}\) and solve for \(a, b, c, d\) in terms of \(v_1\) and \(v_2\); \(P\) should not involve \(u_1\) or \(u_2\). Don’t forget that \(\vec v\) is a unit vector, and both \(\vec u, \vec v \in \mathbb{R}^2\).

Solution

Let’s expand the projection formula:

$$ (\vec u\cdot\vec v)\vec v =\begin{bmatrix}u_1v_1^2+u_2v_1v_2\\\\u_1v_1v_2+u_2v_2^2\end{bmatrix}. $$

The coefficients on \(u_1\) and \(u_2\) give us the entries of \(P\):

$$ \boxed{P=\begin{bmatrix}v_1^2&v_1v_2\\\\v_1v_2&v_2^2\end{bmatrix}}. $$

This works for every \(\vec u\), and only depends on the direction we’re projecting onto.

b)

(4 pts) Find the projection of \(\vec u = \begin{bmatrix} 9 \\ -3 \end{bmatrix}\) onto the unit vector \(\vec v = \begin{bmatrix} 3 / 5 \\ 4 / 5 \end{bmatrix}\) using:

  1. The formula for the projection of \(\vec u\) onto \(\vec v\)

  2. The projection matrix \(P\) you found in part a)

Solution

(i) Using the projection formula,

$$ \vec p=\left(9\cdot\frac35-3\cdot\frac45\right)\begin{bmatrix}3/5\\\\4/5\end{bmatrix} =3\begin{bmatrix}3/5\\\\4/5\end{bmatrix} =\boxed{\begin{bmatrix}9/5\\\\12/5\end{bmatrix}}. $$

(ii) Our projection matrix gives the same result:

$$ P\vec u=\frac1{25}\begin{bmatrix}9&12\\\\12&16\end{bmatrix}\begin{bmatrix}9\\\\-3\end{bmatrix} =\frac1{25}\begin{bmatrix}45\\\\60\end{bmatrix} =\begin{bmatrix}9/5\\\\12/5\end{bmatrix}. $$
c)

(4 pts) Show that \(P\) satisfies the following property:

$$ P^2 = P $$

This means that \(P\) is an idempotent matrix, meaning that applying \(P\) twice (or three times, or four times, etc.) to a vector is the same as applying it once.

Hint: You’ll likely end up with terms of the form \(v_1^4\). Remember that \(\vec v\) is a unit vector; use this to help you simplify.

Solution

Since \(\vec v\) is a unit vector, \(v_1^2+v_2^2=1\). Multiplying gives

$$ \begin{align*} P^2&=\begin{bmatrix}v_1^4+v_1^2v_2^2&v_1^3v_2+v_1v_2^3\\\\v_1^3v_2+v_1v_2^3&v_1^2v_2^2+v_2^4\end{bmatrix}\\\\ &=(v_1^2+v_2^2)\begin{bmatrix}v_1^2&v_1v_2\\\\v_1v_2&v_2^2\end{bmatrix}=P. \end{align*} $$

Once we’ve projected onto the line, projecting again doesn’t move us anywhere!

d)

(1 pt) Use the supplemental Jupyter Notebook we’ve created for Homework 5, which can either be found here on DataHub, or here in the course GitHub repository.

Go to Problem 5d and complete the tasks in that section. There is no autograded code for Problem 5d – instead, include screenshots of your code and its output when you drag the slider to \(30^\circ\).

Solution

For the first plot, fill in

P = np.array([[9/25, 12/25], [12/25, 16/25]])

This gives \(P\vec u=\begin{bmatrix}9/5\\12/5\end{bmatrix}\), as in part (b).

For the explorer at \(30^\circ\), the unit vector along the line is \(\begin{bmatrix}\sqrt3/2\\1/2\end{bmatrix}\), so

$$ P=\frac14\begin{bmatrix}3&\sqrt3\\\\\sqrt3&1\end{bmatrix}. $$

Both projected vectors lie on that line:

$$ P\vec x=\frac14\begin{bmatrix}6+\sqrt3\\\\2\sqrt3+1\end{bmatrix},\qquad P\vec y=\frac14\begin{bmatrix}-3+2\sqrt3\\\\-\sqrt3+2\end{bmatrix}. $$

These are the endpoints you should see in the plot.

e)

(2 pts) Reflect on what you observed above. What angle does the dashed segment make with the projection line? Try a horizontal line, a vertical line, and a tilted line using the slider. Explain how what you see illustrates \(P^2=P\).

Solution

The dashed segment is perpendicular to the projection line, so the angle is \(90^\circ\). This stays true whether the line is horizontal, vertical, or tilted. Once a vector has been projected, it’s already on the line, so projecting it again leaves it where it is. That’s what \(P^2=P\) means geometrically.

f)

(5 pts) Find a matrix \(R\) such that \(R\vec u\) is the reflection of \(\vec u\) across the line spanned by the unit vector \(\vec v\), using the reflection operation you learned about in Homework 4, Problem 4. Express \(R\) in terms of \(P\) and the identity matrix \(I\).

Then show algebraically that \(R^2=I\). Use your equation for \(R\) and the identity \(P^2=P\), rather than expanding the individual entries of \(R\).

Solution

From Homework 4, the reflection is \(2\vec p-\vec u\). Since \(\vec p=P\vec u\), we get

$$ R\vec u=2P\vec u-\vec u=(2P-I)\vec u,\qquad \boxed{R=2P-I}. $$

Now use \(P^2=P\):

$$ R^2=(2P-I)^2=4P^2-4P+I=4P-4P+I=\boxed I. $$

Reflecting across the same line twice takes us back to the original vector.


Problem 6: Orthogonal Matrices (20 pts)

Read the Orthogonal Matrices section of Chapter 5.2 before starting this problem.

a)

(6 pts) Which of the following matrices are orthogonal? For each matrix, explain why or why not it is an orthogonal matrix.

$$ A=\begin{bmatrix}3&0\\\\0&2\\\\4&0\end{bmatrix},\qquad B=\begin{bmatrix}0&0&1\\\\3/5&4/5&0\\\\4/5&-3/5&0\end{bmatrix},\qquad C=\begin{bmatrix}3/5&0&1/\sqrt2\\\\4/5&0&1/\sqrt2\\\\0&1&0\end{bmatrix} $$
Solution

\(A\) is not orthogonal. Its columns are perpendicular, but their lengths are 5 and 2, so they aren’t unit vectors. Also, an orthogonal matrix must be square, and \(A\) isn’t.

\(B\) is orthogonal. Each column has length 1. The dot product of the first two columns is

$$ \frac35\cdot\frac45+\frac45\left(-\frac35\right)=0, $$

and the third column is perpendicular to both. So \(B\) is square with orthonormal columns, which means \(B^TB=BB^T=I\).

\(C\) is not orthogonal. Its columns all have length 1, but the first and third aren’t perpendicular:

$$ \frac35\cdot\frac1{\sqrt2}+\frac45\cdot\frac1{\sqrt2}=\frac7{5\sqrt2}\ne0. $$

Unit-length columns alone aren’t enough!

b)

(3 pts) Explain why the following statement is true: If \(Q\) is an orthogonal matrix, then the rows of \(Q\) form an orthonormal set, in addition to the columns. Hint: Think about what \(Q^TQ\) and \(QQ^T\) each are.

Solution

Since \(Q\) is orthogonal, \(QQ^T=I\). The entry in row \(i\) and column \(j\) of \(QQ^T\) is the dot product of rows \(i\) and \(j\) of \(Q\).

On the diagonal, we get 1, so each row has squared length 1. Off the diagonal, we get 0, so different rows are perpendicular. Together, these tell us that the rows form an orthonormal set.

c)

(2 pts) Use the supplemental Jupyter Notebook we’ve created for Homework 5, which can either be found here on DataHub, or here in the course GitHub repository.

Go to Problem 6c and complete the tasks in that section. There is no autograded code for this problem. Instead, include screenshots of your code and its output when you drag the slider to \(30^\circ\), along with your written observations.

Solution

At \(30^\circ\), both vectors turn \(30^\circ\) counterclockwise. Their lengths stay \(\sqrt5\), and the angle between them stays \(90^\circ\). This is also what we see at the other slider settings: rotation changes direction, but preserves lengths and angles.

Using \(R=\begin{bmatrix}\sqrt3/2&-1/2\\1/2&\sqrt3/2\end{bmatrix}\), the endpoints at \(30^\circ\) are

$$ R\vec x=\begin{bmatrix}\sqrt3-1/2\\\\1+\sqrt3/2\end{bmatrix},\qquad R\vec y=\begin{bmatrix}-\sqrt3/2-1\\\\-1/2+\sqrt3\end{bmatrix}. $$
d)

(3 pts) Prove that an orthogonal matrix preserves the norm of every vector: if \(Q\in\mathbb R^{n\times n}\) is orthogonal and \(\vec x\in\mathbb R^n\), then \(\lVert Q\vec x\rVert=\lVert\vec x\rVert\).

Solution

Let’s write the squared norm as a dot product and use \(Q^TQ=I\):

$$ \begin{align*} \lVert Q\vec x\rVert^2&=(Q\vec x)^T(Q\vec x)\\\\ &=\vec x^TQ^TQ\vec x\\\\ &=\vec x^T\vec x=\lVert\vec x\rVert^2. \end{align*} $$

Both norms are nonnegative, so taking square roots gives \(\boxed{\lVert Q\vec x\rVert=\lVert\vec x\rVert}\).

e)

(4 pts) Where does the rotation matrix come from? Suppose \(\vec u\) and \(\vec v\) are unit vectors in \(\mathbb R^2\). The angle from the positive \(x_1\)-axis to \(\vec u\) is \(\alpha\), and rotating \(\vec u\) counterclockwise by \(\theta\) gives \(\vec v\).

image
  1. Write \(\vec u\) and \(\vec v\) in terms of \(\alpha\) and \(\theta\).

  2. Use the identities below to find a \(2\times2\) matrix \(R\) such that \(R\vec u=\vec v\). Your matrix should involve \(\theta\), but not \(\alpha\).

  3. Explain why the same matrix rotates vectors that aren’t unit vectors by \(\theta\), too.

Hint: Use the angle-addition identities

$$ \cos(\alpha+\theta)=\cos\alpha\cos\theta-\sin\alpha\sin\theta,\qquad \sin(\alpha+\theta)=\sin\alpha\cos\theta+\cos\alpha\sin\theta $$
Solution

(i) A unit vector at angle \(\alpha\) has components \(\cos\alpha\) and \(\sin\alpha\). So,

$$ \vec u=\begin{bmatrix}\cos\alpha\\\\\sin\alpha\end{bmatrix},\qquad \vec v=\begin{bmatrix}\cos(\alpha+\theta)\\\\\sin(\alpha+\theta)\end{bmatrix}. $$

(ii) Expanding with the angle-addition identities gives

$$ \vec v=\begin{bmatrix}\cos\theta\cos\alpha-\sin\theta\sin\alpha\\\\\sin\theta\cos\alpha+\cos\theta\sin\alpha\end{bmatrix} =\underbrace{\begin{bmatrix}\cos\theta&-\sin\theta\\\\\sin\theta&\cos\theta\end{bmatrix}}_{R}\vec u. $$

(iii) Any nonzero vector is \(r\vec u\) for some unit vector \(\vec u\) and length \(r>0\). Matrix multiplication gives \(R(r\vec u)=rR\vec u\), so we get the rotated direction with the original length. The zero vector stays at the origin.

f)

(2 pts) Prove that the rotation matrix \(R\) you found in part e) is orthogonal for every angle \(\theta\).

Hint: Use \(\cos^2(\theta)+\sin^2(\theta)=1\).

Solution

The columns of \(R\) are \(\begin{bmatrix}\cos\theta\\\sin\theta\end{bmatrix}\) and \(\begin{bmatrix}-\sin\theta\\\cos\theta\end{bmatrix}\). Each has squared length \(\cos^2\theta+\sin^2\theta=1\), and their dot product is

$$ \cos\theta(-\sin\theta)+\sin\theta\cos\theta=0. $$

So \(R\) is square with orthonormal columns, and hence is orthogonal for every \(\theta\).


Problem 7: Rank and CR Decomposition (10 pts)

The rank of a matrix is the dimension of the span of its columns. We call the span of a matrix’s columns its column space.

Read the CR Decomposition section of Chapter 5.4 before starting this problem. There, we introduce the concept of a CR decomposition. As another example, let \(A\) be the matrix from Homework 4, Problem 6.

Its CR decomposition is:

$$ A = \underbrace{\begin{bmatrix} 5 & 3 & 2 \\\\ 3 & 0 & 4 \\\\ -2 & 0 & 3 \\\\ 8 & 2 & -8 \\\\ 1 & 1 & 0 \end{bmatrix}}_{C} \underbrace{\begin{bmatrix} 1 & 0 & -2 & 0 \\\\ 0 & 1 & 5 & 0 \\\\ 0 & 0 & 0 & 1 \end{bmatrix}}_{R} $$

To understand where the numbers in \(R\) came from, read the solutions to Homework 4, linked above.

For each matrix below, by hand:

  1. Find a CR decomposition, choosing the columns of \(C\) from left to right.

  2. Find the rank of \(A\). How is it related to the number of columns in \(C\)?

  3. Can you find a nonzero vector \(\vec v\) such that \(A\vec v=\vec 0\)? If so, give an example. If not, explain why not.

Hint: Look for relationships between the columns; this is not meant to be time consuming.

a)

(3 pts) \(A=\begin{bmatrix}1&2&3\\4&5&6\\7&8&9\end{bmatrix}\)

Solution

The first two columns aren’t scalar multiples, so they’re linearly independent. The third is \(-1\) times the first plus 2 times the second. So,

$$ \boxed{C=\begin{bmatrix}1&2\\\\4&5\\\\7&8\end{bmatrix},\qquad R=\begin{bmatrix}1&0&-1\\\\0&1&2\end{bmatrix}}. $$

The rank is \(\boxed2\), the number of columns in \(C\). Moving our column relationship to one side gives column 1 minus 2 times column 2 plus column 3 equal to zero, so

$$ \boxed{\vec v=\begin{bmatrix}1\\\\-2\\\\1\end{bmatrix}} $$

is one nonzero vector with \(A\vec v=\vec0\).

b)

(3 pts) \(A=\begin{bmatrix}3&5\\1&1\\2&-4\\30&0\end{bmatrix}\)

Solution

The two columns aren’t scalar multiples, so they’re linearly independent. We keep both:

$$ \boxed{C=\begin{bmatrix}3&5\\\\1&1\\\\2&-4\\\\30&0\end{bmatrix},\qquad R=\begin{bmatrix}1&0\\\\0&1\end{bmatrix}}. $$

The rank is \(\boxed2\), again the number of columns in \(C\). There is no nonzero \(\vec v\) with \(A\vec v=\vec0\), since linear independence means the only coefficients that give the zero vector are both zero.

c)

(4 pts) \(A=\begin{bmatrix}1&-2&3&-1\\-2&4&1&-5\\3&-6&4&2\\0&0&5&-5\end{bmatrix}\)

Solution

Column 2 is \(-2\) times column 1, so we skip it. Column 3 isn’t a multiple of column 1, so we keep it. Finally, column 4 is 2 times column 1 minus column 3. This gives

$$ \boxed{C=\begin{bmatrix}1&3\\\\-2&1\\\\3&4\\\\0&5\end{bmatrix},\qquad R=\begin{bmatrix}1&-2&0&2\\\\0&0&1&-1\end{bmatrix}}. $$

The rank is \(\boxed2\), the number of columns in \(C\). Since 2 times column 1 plus column 2 is zero, one choice is

$$ \boxed{\vec v=\begin{bmatrix}2\\\\1\\\\0\\\\0\end{bmatrix}}. $$

Problem 8: Random Matrices, Rank, and Cosine Similarity (8 pts)

Use the supplemental Jupyter Notebook we’ve created for Homework 5, which can either be found here on DataHub, or here in the course GitHub repository.

Go to Problem 8. For this problem, you will use simulations to explore the typical rank of a randomly generated matrix, and see how the cosine similarities between randomly generated vectors change as their number of components increases.

All code is provided. There is no autograded code or notebook submission for this problem. Include the following in your regular Homework 5 PDF under Problem 8:

  • Task 1 (1 pt): Your handwritten explanation of the Gaussian matrix ranks.

  • Task 2 (2 pts): Your handwritten explanation of the Gaussian matrix product ranks.

  • Task 3 (3 pts): Your handwritten responses to both questions about binary matrix product ranks.

  • Task 4 (2 pts): Your handwritten responses to both questions about cosine similarity.

Your submission time for Homework 5 is the later of the two submission times: your Problem 1 video link and your regular Homework 5 PDF.

Solution

Task 1. The rank is almost always 3 because the columns span \(\mathbb R^3\): with independent Gaussian entries, an exact linear dependence among the first three columns has probability zero.

Task 2. The largest possible rank is \(\boxed3\), since the product has only 3 rows. We also almost always observe rank 3. To see why, call the factors \(A\) and \(B\). The columns of the \(4\times5\) matrix \(B\) almost surely span \(\mathbb R^4\). Applying \(A\) to those columns therefore spans the entire column space of \(A\), which almost surely has dimension 3.

Task 3. With binary entries, exact dependencies have positive probability. For instance, a column can be all zeros, or two columns can be identical. Either factor can lose rank this way, and the product can’t have more rank than either factor. That’s why we see several possible ranks, especially for the \(3\times3\) products.

As the matrices get larger, the plots concentrate near full rank. One way to build intuition is to look at a particular pair of columns: the probability that they match in every entry is \(2^{-n}\). The probability that a particular column is all zeros is also \(2^{-n}\). These simple dependencies become much less likely as \(n\) grows. There are other ways to be dependent, too, so this is intuition for the pattern, rather than a proof covering every possible dependency.

Task 4. As \(n\) increases, the cosine similarities concentrate around 0. In other words, two independent random Gaussian vectors are increasingly likely to be nearly perpendicular. They aren’t usually exactly perpendicular; the angle is just close to \(90^\circ\).

The “curse of dimensionality” refers to difficulties that arise when we have many features. For example, data become sparse in a high-dimensional space, and similarity becomes less useful for distinguishing points when most pairs have nearly the same similarity. This experiment illustrates that issue: as the number of components grows, most pairs of these random vectors have cosine similarity close to 0.