Lab 11: Diagonalization, Spectral Theorem, SVD

due by the end of your lab section on Wednesday, December 2nd, 2026

Each lab worksheet will contain several activities, some of which will involve writing code and others that will involve writing math on paper. To receive credit for a lab, you must complete all activities and show your lab TA by the end of the lab section.

While you must get checked off by your lab TA individually, we encourage you to form groups with 1-2 other students to complete the activities together.


Activities


Activity 1: Fundamentals

Let \(A = \begin{bmatrix} 3 & 2 & 0 \\ 2 & 3 & 0 \\ 0 & 0 & 5 \end{bmatrix}\).

a)

Find the eigenvalues of \(A\) and their algebraic multiplicities. Hint: Be efficient; use the fact that \(A\) is block diagonal.

Solution

The eigenvalues of a block diagonal matrix come from combining the eigenvalues of its blocks, counting multiplicities. Here the blocks are

$$ A_1 = \begin{bmatrix}3 & 2 \\\\ 2 & 3\end{bmatrix}, \qquad A_2 = \begin{bmatrix}5\end{bmatrix} $$

For \(A_1\), adding its columns gives \(\begin{bmatrix}5 \\ 5\end{bmatrix}\), and subtracting its second column from its first gives \(\begin{bmatrix}1 \\ -1\end{bmatrix}\). In other words,

$$ A_1\begin{bmatrix}1 \\\\ 1\end{bmatrix} = 5\begin{bmatrix}1 \\\\ 1\end{bmatrix}, \qquad A_1\begin{bmatrix}1 \\\\ -1\end{bmatrix} = 1\begin{bmatrix}1 \\\\ -1\end{bmatrix} $$

So \(A_1\) contributes one \(5\) and one \(1\). The \(1\times1\) block \(A_2\) contributes another \(5\). Combining the two blocks gives \(\boxed{\mathrm{AM}(1)=1}\) and \(\boxed{\mathrm{AM}(5)=2}\).

b)

Recall that \(A=\left[\begin{smallmatrix}3&2&0\\2&3&0\\0&0&5\end{smallmatrix}\right]\).

Find a basis for the eigenspace corresponding to each eigenvalue.

Solution

Extend each eigenvector of \(A_1\) from part (a) by putting a zero in the third coordinate. The block \(A_2\) contributes one more eigenvector for \(\lambda=5\), the vector along the third coordinate axis. This gives the following bases:

$$ \lambda=1:\quad \left\{\begin{bmatrix}1\\\\-1\\\\0\end{bmatrix}\right\}, \qquad \lambda=5:\quad \left\{\begin{bmatrix}1\\\\1\\\\0\end{bmatrix}, \begin{bmatrix}0\\\\0\\\\1\end{bmatrix}\right\} $$
c)

This particular \(A\) is diagonalizable. Diagonalize \(A\) by finding a matrix \(V\) and a diagonal matrix \(\Lambda\) such that \(A = V \Lambda V^{-1}\).

Solution

In the previous part, we saw that \(\lambda_1 = 1\) has the eigenvector \(\vec v_1 = \begin{bmatrix} 1 \\ -1 \\ 0 \end{bmatrix}\), while \(\lambda_2 = 5\) corresponds to the linearly independent eigenvectors \(\begin{bmatrix} 1 \\ 1 \\ 0 \end{bmatrix}\) and \(\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}\). So, we can construct \(V\) and \(\Lambda\) as follows:

$$ V = \begin{bmatrix} 1 & 1 & 0 \\\\ -1 & 1 & 0 \\\\ 0 & 0 & 1 \end{bmatrix}, \quad \Lambda = \begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 5 & 0 \\\\ 0 & 0 & 5 \end{bmatrix} $$

And we have \(A = V \Lambda V^{-1} = \begin{bmatrix} 1 & 1 & 0 \\ -1 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 5 & 0 \\ 0 & 0 & 5 \end{bmatrix} \begin{bmatrix} 1/2 & -1/2 & 0 \\ 1/2 & 1/2 & 0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 3 & 2 & 0 \\ 2 & 3 & 0 \\ 0 & 0 & 5 \end{bmatrix}\).

d)

Adapted from Fall 2025 Final Exam, Problem 9(c). Suppose \(B=\begin{bmatrix}2&1\\c&6\end{bmatrix}\) has real eigenvalues and is not diagonalizable. Find \(c\) and both eigenvalues of \(B\). Justify your answer.

Solution

Two distinct eigenvalues would give two linearly independent eigenvectors, so the eigenvalues must be equal. Their sum is \(\operatorname{trace}(B)=8\), so both are \(\boxed{4}\). Their product is \(\det(B)=12-c\), so \(16=12-c\) gives \(\boxed{c=-4}\).

For this value, \(B-4I=\begin{bmatrix}-2&1\\-4&2\end{bmatrix}\) has rank 1. Its null space has dimension 1, so the repeated eigenvalue has only one linearly independent eigenvector.


Activity 2: Symmetric Matrices

Suppose \(A\) is a symmetric \(n \times n\) matrix, meaning \(A = A^T\). Symmetric matrices have a special property, described by the spectral theorem: the eigenvectors corresponding to different eigenvalues are orthogonal. Below, we provide a proof of this fact.

1. Let \(\vec v_i\) be an eigenvector of \(A\) with eigenvalue \(\lambda_i\), so \(A \vec v_i = \lambda_i \vec v_i\).

2. Let \(\vec v_j\) be an eigenvector of \(A\) with eigenvalue \(\lambda_j\), where \(\lambda_i \neq \lambda_j\), so \(A \vec v_j = \lambda_j \vec v_j\).

3. The dot product of \(\vec v_i\) and \(A \vec v_j\) is \(\vec v_i \cdot (A \vec v_j) = \vec v_i \cdot (\lambda_j \vec v_j) = \lambda_j (\vec v_i \cdot \vec v_j)\).

4. But also, \(\vec v_i \cdot (A \vec v_j) = \vec v_i^T A \vec v_j = \vec v_i^T A^T \vec v_j = (A \vec v_i)^T \vec v_j = \lambda_i \vec v_i^T \vec v_j = \lambda_i (\vec v_i \cdot \vec v_j)\).

5. The final expressions in both cases are equal, so \(\lambda_j (\vec v_i \cdot \vec v_j) = \lambda_i (\vec v_i \cdot \vec v_j)\).

6. Equivalently, \((\lambda_j - \lambda_i) (\vec v_i \cdot \vec v_j) = 0\). But since \(\lambda_i \neq \lambda_j\), we must have \(\vec v_i \cdot \vec v_j = 0\).

a)

In which line did we use the fact that \(A\) is symmetric? Select the line below, and then in that line, circle the specific part of the equation that uses the fact that \(A = A^T\).

1 2 3 4 5 6
Solution
1 2 3 4 5 6

Line 4 is the only line that uses the fact that \(A = A^T\), but it’s the most important line in the proof. Specifically, here’s where we used that fact:

$$ \vec v_i^T A \vec v_j = \vec v_i^T A^T \vec v_j $$

By using \(A = A^T\) here, we were able to write \(\vec v_i \cdot (A \vec v_j)\) as \(\vec v_i^T A^T \vec v_j = (A \vec v_i) \cdot \vec v_j\), which was key to our final expression.

b)

The spectral theorem states that any symmetric \(n \times n\) matrix \(A\) can be diagonalized by an orthogonal matrix \(Q\) through

$$ A = Q \Lambda Q^T $$

Explain how this relates to the “regular” diagonalization \(A = V \Lambda V^{-1}\). Why does the equation above contain \(Q^T\) instead of \(Q^{-1}\)?

Solution

A standard (not necessarily symmetric) matrix \(A\) that is diagonalizable can be written as

$$ A = V \Lambda V^{-1} $$

If \(A\) is symmetric and can be written \(A = Q \Lambda Q^T\), then the fact that we have \(Q^T\) instead of \(Q^{-1}\) stems from the fact that orthogonal matrices satisfy \(Q^T = Q^{-1}\). This comes from the fact that \(Q^TQ = QQ^T = I\). Transposes are easier to compute than inverses, and easier to interpret, too: if \(Q\) is a rotation, then \(Q^T\) is the inverse rotation, i.e. a rotation by the opposite amount.

c)

Symmetric matrices play a big role in solving optimization problems in machine learning. You’ll get a taste of this in Homework 10, Problem 7, which discusses ridge regression and regularization, ideas that we use to make sure that our models are not overfitting to training data.

Here, we’ll prove a related fact: if \(A\) is an \(n \times n\) symmetric matrix and all of its eigenvalues are non-negative, then \(A\) is positive semidefinite. A symmetric matrix \(A\) is positive semidefinite if and only if \(\boxed{\vec v^T A \vec v \geq 0}\) for all \(\vec v \in \mathbb{R}^n\). One interpretation: this means the quadratic form \(f(\vec v) = \vec v^T A \vec v\) is always greater than or equal to 0, no matter what \(\vec v\) is.

Let’s work through the proof step-by-step: we will do some of it for you, and you’ll complete the rest. (To be precise, we’re only proving one direction of the “if and only if” statement; Homework 10, Problem 7c, proves the related fact that \(X^TX\) has non-negative eigenvalues!) First, since \(A\) is symmetric, the spectral theorem tells us that \(A\) can be written as

$$ A = Q \Lambda Q^T $$

where \(Q\) is an orthogonal matrix and \(\Lambda\) is a diagonal matrix with the eigenvalues of \(A\) on the diagonal. This is the eigenvector decomposition of \(A\).

On top of that, suppose that all of \(A\)’s eigenvalues, \(\lambda_1, \lambda_2, \ldots, \lambda_n\), are non-negative.

Now, let \(\vec v\) be some arbitrary vector (not necessarily an eigenvector of \(A\)) in \(\mathbb{R}^n\). Then, eventually we need to show that \(\vec v^T A \vec v \geq 0\), regardless of what \(\vec v\) is. Let’s start by expanding \(\vec v^T A \vec v\) using the fact that \(A = Q \Lambda Q^T\).

$$ \vec v^T A \vec v = \vec v^T (Q \Lambda Q^T) \vec v = (\vec v^T Q) \Lambda (Q^T \vec v) $$

Suppose that \(\vec y = Q^T \vec v\). Then, \(\vec y^T = (Q^T \vec v)^T = \vec v^T Q\). This seems like an arbitrary maneuver, but it will be useful in a moment.

$$ \begin{align*} \vec v^T A \vec v &= \vec y^T \Lambda \vec y =\begin{bmatrix} y_1 & y_2 & \ldots & y_n \end{bmatrix} \begin{bmatrix} \lambda_1 & 0 & \ldots & 0 \\\\ 0 & \lambda_2 & \ldots & 0 \\\\ \vdots & \vdots & \ddots & \vdots \\\\ 0 & 0 & \ldots & \lambda_n \end{bmatrix} \begin{bmatrix} y_1 \\\\ y_2 \\\\ \vdots \\\\ y_n \end{bmatrix} \end{align*} $$

Your job is to complete the rest of the proof. Show that if \(A\) is an \(n \times n\) symmetric matrix and all of its eigenvalues are non-negative, then \(\vec v^T A \vec v \geq 0\) for all \(\vec v \in \mathbb{R}^n\).

Solution
$$ \begin{align*} \vec v^T A \vec v &= \vec y^T \Lambda \vec y \\\\ &= \begin{bmatrix} y_1 & y_2 & \ldots & y_n \end{bmatrix} \begin{bmatrix} \lambda_1 & 0 & \ldots & 0 \\\\ 0 & \lambda_2 & \ldots & 0 \\\\ \vdots & \vdots & \ddots & \vdots \\\\ 0 & 0 & \ldots & \lambda_n \end{bmatrix} \begin{bmatrix} y_1 \\\\ y_2 \\\\ \vdots \\\\ y_n \end{bmatrix} \\\\ &= \begin{bmatrix} y_1 & y_2 & \ldots & y_n \end{bmatrix} \begin{bmatrix} \lambda_1 y_1 \\\\ \lambda_2 y_2 \\\\ \vdots \\\\ \lambda_n y_n \end{bmatrix} \\\\ &= \sum_{i=1}^n \lambda_i y_i^2 \end{align*} $$

Remember that none of the \(\lambda_i\)’s are negative. So, each term \(\lambda_i y_i^2\) is non-negative too, meaning the entire sum \(\sum_{i=1}^n \lambda_i y_i^2\) is non-negative. What we’ve shown is that if \(\vec v\) is any vector in \(\mathbb{R}^n\), then \(\vec v^T A \vec v\) ends up being a sum of this form, which is always non-negative, so \(\vec v^T A \vec v \geq 0\), and thus \(A\) is positive semidefinite.


Activity 3: Quadratic Forms Return

Open Desmos in 3D mode at desmos.com/3d and write \(z = x^{2}+2bxy+16y^{2}\). This should show you a 3D surface along with a slider for \(b\). Drag the slider to see how the shape of the surface changes for different \(b\)’s. You should notice that depending on the value of \(b\), the surface may or may not have a global minimum. Let’s explore!

a)

\(z\) is a quadratic form, \(f(\vec x) = \vec x^T A \vec x\), where \(\vec x = \begin{bmatrix} x \\ y \end{bmatrix}\) and \(A\) is a symmetric matrix. Find \(A\).

Solution

\(A = \begin{bmatrix} 1 & b \\ b & 16 \end{bmatrix}\).

To see where this comes from, let’s expand \(f(\vec x) = \vec x^T A \vec x\):

$$ \begin{align*} f(\vec x) &= \vec x^T A \vec x \\\\ &= \begin{bmatrix} x & y \end{bmatrix} \begin{bmatrix} 1 & b \\\\ b & 16 \end{bmatrix} \begin{bmatrix} x \\\\ y \end{bmatrix} \\\\ &= \begin{bmatrix} x & y \end{bmatrix} \begin{bmatrix} x + by \\\\ bx + 16y \end{bmatrix} \\\\ &= x(x + by) + y(bx + 16y) \\\\ &= x^2 + bxy + bxy + 16y^2 \\\\ &= x^2 + 2bxy + 16y^2 \end{align*} $$

So, \(A = \begin{bmatrix} 1 & b \\ b & 16 \end{bmatrix}\).

b)

For a vector-to-scalar function \(f: \mathbb{R}^n \to \mathbb{R}\), the Hessian of \(f\), denoted \(\nabla^2 f\), is the \(n \times n\) matrix of second partial derivatives of \(f\). Find \(\nabla^2 f\) for \(f(\vec x) = \vec x^T A \vec x\).

Solution

\(\nabla^2 f = \begin{bmatrix} 2 & 2b \\ 2b & 32 \end{bmatrix}\).

To find the second partial derivatives of \(f\), we first find the first partial derivatives:

$$ \begin{align*} f(\vec x) = \vec x^T A \vec x &= x^2 + 2bxy + 16y^2 \\\\ \frac{\partial f}{\partial x} &= 2x + 2by \\\\ \frac{\partial f}{\partial y} &= 2bx + 32y \end{align*} $$

Since there are two first partial derivatives, there are \(2 \times 2 = 4\) second partial derivatives. We can find them all by taking the partial derivatives of the first partial derivatives:

$$ \begin{align*} \frac{\partial^2 f}{\partial x^2} &= \frac{\partial}{\partial x} \left( 2x + 2by \right) = 2 \\\\ \frac{\partial^2 f}{\partial x \partial y} &= \frac{\partial}{\partial y} \left( 2x + 2by \right) = 2b \\\\ \frac{\partial^2 f}{\partial y \partial x} &= \frac{\partial}{\partial x} \left( 2bx + 32y \right) = 2b \\\\ \frac{\partial^2 f}{\partial y^2} &= \frac{\partial}{\partial y} \left( 2bx + 32y \right) = 32 \end{align*} $$

Note that \(\frac{\partial^2 f}{\partial x \partial y} = \frac{\partial^2 f}{\partial y \partial x}\), which is a general property of second partial derivatives — it doesn’t matter which order we take the derivatives in. So, the Hessian is

$$ \nabla^2 f = \begin{bmatrix} 2 & 2b \\\\ 2b & 32 \end{bmatrix} $$

Notice that this is just \(2A\)!

c)

A symmetric matrix \(A\) is positive semidefinite (PSD) if \(\vec v^T A \vec v \geq 0\) for all \(\vec v \in \mathbb{R}^n\). In English, this says that \(A\) is positive semidefinite if the quadratic form \(f(\vec v) = \vec v^T A \vec v\) is always non-negative for all \(\vec v \in \mathbb{R}^n\). Two relevant facts:

  • A twice continuously differentiable vector-to-scalar function \(f\) is convex if its Hessian is PSD.

  • A symmetric matrix \(A\) is PSD if and only if all of its eigenvalues are non-negative.

Using the facts above, find the range of values \(b\) for which \(f\) is convex, and verify your answer by dragging the slider on Desmos.

Solution

As long as \(-4 \leq b \leq 4\), the Hessian is PSD, and \(f\) is convex.

Recall from the previous part that the Hessian is

$$ \nabla^2 f = \begin{bmatrix} 2 & 2b \\\\ 2b & 32 \end{bmatrix} = 2A $$

\(f\) is convex if and only if \(2A\) is PSD, which means that both of \(2A\)’s eigenvalues are non-negative. Let \(\lambda_1\) and \(\lambda_2\) be \(2A\)’s eigenvalues. Then, we need \(\lambda_1 \geq 0\) and \(\lambda_2 \geq 0\). How do we ensure this?

Let’s recall the facts about the trace and determinant:

  • The sum of \(2A\)’s eigenvalues, \(\lambda_1 + \lambda_2\), is equal to the trace of \(2A\), \(\text{trace}(2A)\), which is the sum of the diagonal entries of \(2A\). Here, this is \(2 + 32 = 34\).

  • The product of \(2A\)’s eigenvalues, \(\lambda_1 \lambda_2\), is equal to the determinant of \(2A\), \(\det(2A)\), which is \(2 \cdot 32 - (2b)^2 = 64 - 4b^2\).

The fact that \(\lambda_1 + \lambda_2 = 34\) means that no matter what \(b\) is, at least one of the eigenvalues is non-negative, since you can’t add two negative numbers and get a positive sum.

So, let’s focus our attention on the product of the eigenvalues, \(\lambda_1 \lambda_2 = 64 - 4b^2\). We need this to be \(\geq 0\), because if it were negative, then one of the eigenvalues would be negative (since multiplying a positive number by a negative number gives a negative number).

Using this reasoning, we need \(64 - 4b^2 \geq 0\), which simplifies to \(4b^2 \leq 64\), which simplifies to \(b^2 \leq 16\), which simplifies to \(-4 \leq b \leq 4\). If \(|b| > 4\), then one of the eigenvalues would be negative, \(2A\) would not be PSD, and \(f\) would not be convex.

Notice that in this case, the “test” for convexity ended up simplifying to checking whether the determinant of \(A\) is non-negative. That is true, in general, for quadratic forms \(f(\vec x) = \vec x^T A \vec x\) where \(A\) is a \(2 \times 2\)symmetric matrix. But if \(A\) is \(3 \times 3\) or larger, the determinant test alone isn’t sufficient; it’s possible to have a positive determinant and trace but a negative eigenvalue in a \(3 \times 3\) matrix. What is true in general is that if \(A\) is a symmetric \(n \times n\) matrix, then \(f(\vec x) = \vec x^T A \vec x\) is convex if and only if all of \(A\)’s eigenvalues are non-negative.


Introduction: Singular Value Decomposition

(Chapters 10.1 and 10.2)

Suppose \(X\) is any \(n \times d\) matrix. Then, there exists a singular value decomposition (SVD) of \(X\) of the form

$$ X = U \Sigma V^T $$

where:

MatrixShapeValues Come FromProperties
\(U\)\(n \times n\)Columns are eigenvectors of \(XX^T\), called the left singular vectors of \(X\)Orthogonal, \(U^TU = UU^T = I_{n \times n}\)
\(\Sigma\)\(n \times d\)Each singular value \(\sigma_i\) is the square root of the \(i\)-th largest eigenvalue of \(X^TX\) (or \(XX^T\))Diagonal, with value in position \((i, i)\) equal to \(\sigma_i\) for \(i=1,2,\dots,r = \text{rank}(X)\)
\(V\)\(d \times d\)Columns are eigenvectors of \(X^TX\), called the right singular vectors of \(X\)Orthogonal, \(V^TV = VV^T = I_{d \times d}\)

If \(\vec u_i\) and \(\vec v_i\) are the \(i\)-th left and right singular vectors of \(X\), respectively, then

$$ \boxed{X\vec v_i = \sigma_i\vec u_i} $$

In matrix form, this is \(XV = U\Sigma\), or equivalently, \(X = U\Sigma V^T\).

Where do the definitions in the table come from? If \(X\) is \(n \times d\), then \(X^TX\) is \(d \times d\) and \(XX^T\) is \(n \times n\). Both are square and symmetric. Substituting \(X=U\Sigma V^T\) and using \(U^TU=I\) and \(V^TV=I\) gives

$$ \begin{align*} X^TX &= (V\Sigma^T U^T)(U\Sigma V^T) = V(\Sigma^T\Sigma)V^T \\\\ XX^T &= (U\Sigma V^T)(V\Sigma^T U^T) = U(\Sigma\Sigma^T)U^T \end{align*} $$

These are the decompositions from the spectral theorem applied to \(X^TX\) and \(XX^T\). In the first equation, the columns of \(V\) are orthonormal eigenvectors of \(X^TX\), and their eigenvalues are the diagonal entries of \(\Sigma^T\Sigma\). In the second, the columns of \(U\) are orthonormal eigenvectors of \(XX^T\), and their eigenvalues are the diagonal entries of \(\Sigma\Sigma^T\). Both diagonal matrices have the same nonzero entries \(\sigma_1^2,\ldots,\sigma_r^2\), where \(r=\operatorname{rank}(X)\).


Activity 4: SVD Fundamentals

Suppose the matrix \(X\) has the singular value decomposition \(X=U\Sigma V^T\) where

$$ U = \begin{bmatrix}0 & 1 \\\\ 1 & 0\end{bmatrix}, \quad \Sigma = \begin{bmatrix}\sigma_1 & 0 & 0 \\\\ 0 & 2 & 0 \end{bmatrix}, \quad V = \begin{bmatrix}1/\sqrt{2} & | & 0 \\\\ 0 & \vec v_2 & 1 \\\\ 1/\sqrt{2} & | & 0 \end{bmatrix} $$
a)

How many rows and columns does \(X\) have? What is \(\text{rank}(X)\)?

Solution

\(X\) is a \(2 \times 3\) matrix, matching the dimensions of \(\Sigma\). \(\text{rank}(X)\) is 2, since there are 2 non-zero singular values.

b)

Find \(\vec v_2\).

Solution

\(\vec v_2\) is a unit eigenvector of \(X^TX\) with eigenvalue \(\sigma_2^2=4\). It’s also a unit vector, meaning we need to find a unit vector that’s orthogonal to the other two columns, so \(\vec v_2 = \begin{bmatrix}\sqrt{2} / 2 \\ 0 \\ -\sqrt{2} / 2 \end{bmatrix}\) or its negative.

c)

Given that the first column of \(X\) and third column of \(X\) sum to \(\begin{bmatrix}0 \\ 5\end{bmatrix}\), find \(\sigma_1\).

Solution
$$ \begin{align*} X\vec v_1 &= \sigma_1 \vec u_1 \\\\X\begin{bmatrix}1/\sqrt{2} \\\\ 0 \\\\ 1/\sqrt{2}\end{bmatrix} &= \sigma_1 \begin{bmatrix}0 \\\\ 1\end{bmatrix} \end{align*} $$

The left side of the equation is the sum of \(X\)’s first and third columns, scaled by \(1 / \sqrt{2}\), so we can use the fact given in the problem here:

$$ \begin{align*} \frac{1}{\sqrt{2}}\begin{bmatrix}0 \\\\ 5\end{bmatrix} &= \sigma_1\begin{bmatrix}0 \\\\ 1\end{bmatrix} \\\\ \begin{bmatrix}0 \\\\ 5/\sqrt{2}\end{bmatrix} &= \begin{bmatrix}0 \\\\ \sigma_1\end{bmatrix} \\\\ \sigma_1 &= \frac{5\sqrt{2}}{2} \end{align*} $$