4 pts Find \(\nabla f(\vec x)\), the gradient of \(f(\vec x)\). Show your work, and \(\boxed{\text{circle}}\) your final answer, which should be an expression in terms of \(\vec x\), \(S\), \(\vec b\), and/or constants. Hint: There’s no need to re-prove gradient rules from class.
Chapter 8: Gradients
Topics: gradient vector, gradients + matrix/vector operations, gradient descent, convexity, positive definite matrices
Problems below are collected from past exams; each links back to its full exam. Solutions are in the dropdowns.
Problems
- FA25 MT2 · Problem 6
- FA25 MT2 · Problem 7
- FA25 Final · Problem 6
- FA25 Final · Problem 7
- WN26 MT2 · Problem 7
- WN26 MT2 · Problem 8
- WN26 Final · Problem 8
- SP26 MT2 · Problem 6
- SP26 MT2 · Problem 7
- SP26 Final · Problem 9
FA25 MT2 · Problem 6: Quadratus Formulus 14 pts
From FA25 MT2
Let \(\displaystyle f(\vec x) = \frac{1}{2} \vec x^T S \vec x - \vec b^T \vec x\), where \(S\) is a symmetric \(n \times n\) matrix and \(\vec b \in \mathbb{R}^n\).
2 pts True or False: As long as \(S\) is invertible, if \(\nabla f(\vec a) = \vec 0\), then \(\vec a\) is a global minimum of \(f(\vec x)\).
Solution
In general, this is false. Even if \(S\) is invertible, \(\nabla f(\vec a) = \vec 0\) could mean that \(\vec a\) is at a local maxima, local minima, or saddle point.
For example, let \(\vec x = \begin{bmatrix} x \\ y \end{bmatrix}\), \(\vec b = \begin{bmatrix} 0 \\ 0 \end{bmatrix}\), and \(S = \begin{bmatrix} 2 & 0 \\ 0 & -2 \end{bmatrix}\), which is an invertible matrix. Then,
but \(f(\vec x) = x^2 - y^2\) has no global minimum, since you can make \(f(\vec x)\) arbitrarily negative by setting \(x = 0\) and \(y = -\text{large number}\).
2 pts True or False: As long as all of the components of \(S\) are positive real numbers, if
\(\nabla f(\vec a) = \vec 0\), then \(\vec a\) is a global minimum of \(f(\vec x)\).
Solution
This is also false. Even if all of the components of \(S\) are positive real numbers, \(f(\vec x)\) may not have a global minimum. As we saw later in the semester, the convexity of \(f\) has to do with whether or not \(S\) is positive semidefinite. But, this was not a concept we knew about on the midterm, so the problem is answerable without that concept.
Instead, the way to think through this is through counterexamples. For example, let \(\vec x = \begin{bmatrix} x \\ y \end{bmatrix}\), \(\vec b = \begin{bmatrix} 1 \\ 0 \end{bmatrix}\), and \(S = \begin{bmatrix} 2 & 4 \\ 4 & 8 \end{bmatrix}\), which is a symmetric matrix with all positive real components. Then,
\(f(\vec x)\) has no global minimum, since you can keep decreasing the output by picking a really large positive value of \(x\) and set \(y = -\frac{x}{2}\), which makes
6 pts We’d like to use gradient descent to minimize \(f(\vec x)\). Suppose \(S = \begin{bmatrix} 2 & 0 \\ 0 & 6 \end{bmatrix}\), \(\vec b = \begin{bmatrix} 1 \\ -4 \end{bmatrix}\), and we use a learning rate of \(\alpha = 1\). After one iteration of gradient descent, we have \(\vec x^{(1)} = \begin{bmatrix} - 2 \\ -4 \end{bmatrix}\). What was our initial guess, \(\vec x^{(0)}\)? Show your work, and \(\boxed{\text{circle}}\) your final answer, which should be a vector with two entries and no variables.
Solution
The gradient update rule is \(\vec x^{(t+1)} = \vec x^{(t)} - \alpha \nabla f(\vec x^{(t)})\). Plugging in \(\alpha = 1\) and \(t = 0\) simplifies our problem to
Now, all we need to do is substitute our known vector \(\vec x^{(1)} = \begin{bmatrix} - 2 \\ -4 \end{bmatrix}\) and matrix \(S\) into the above equation and solve for \(\vec x^{(0)}\).
So, our initial guess was
FA25 MT2 · Problem 7: Complexity 10 pts
From FA25 MT2
Suppose \(f: \mathbb{R} \to \mathbb{R}\) is a convex function.
4 pts Find scalars \(a\) and \(b\) such that \(f(3) \leq a f(2) + b f(6)\). Show your work and \(\boxed{\text{circle}}\) your final answer, which should be a pair of scalars.
Solution
Recall the definition of convexity (which is relevant, since \(f\) is told to us to be convex):
Matching the right-side of the inequality above to the right-side of the inequality given, we see that \(a = 1-t\) and \(b = t\).
So, our job is to find \(1-t\) and \(t\) such that
i.e. \(\textbf{to write 3 as a linear combination of 2 and 6}\).
So, \(\boxed{a = \frac{3}{4}, b = \frac{1}{4}}\).
6 pts Using the result from part a), prove that \(f(3) + f(5) \leq f(2) + f(6)\).
Solution
In part a), we proved
Since there’s an \(f(5)\) in the left side of expression we want to prove, we need to find an inequality for \(f(5)\) in terms of \(f(2)\) and \(f(6)\).
Trying to match the pattern, let \(t = \frac{3}{4}\), and keep \(x = 2\) and \(y = 6\). Where did \(t = \frac{3}{4}\) come from? You could have found it from solving \((1-t) \cdot 2 + t \cdot 6 = 5\), or by guessing/observing that no other value of \(t\) would eventually allow us to add the two inequalities together to get \(f(2) + f(6)\) on the right.
Let’s add this to our previous inequality.
as required!
FA25 Final · Problem 6 4 pts MT2 Redemption
From FA25 Final
Suppose \(A\) and \(B\) are both (not necessarily symmetric!) \(n \times n\) matrices. Which of the following is \(\nabla f(\vec x)\), the gradient of
Solution
We can rewrite the function as
If \(M\) is any matrix, then
Here, \(M = A^TB\), so
FA25 Final · Problem 7 6 pts MT2 Redemption
From FA25 Final
Consider the function \(f: \mathbb{R} \to \mathbb{R}\) graphed below.

Note that \(f\) is a piecewise linear function, with slopes of \(0\), \(4\), and \(-4\). The slope changes at the following values of \(x\): \(-6, -5, -2, -1, 1, 2, 5, 6\).
Suppose we want to minimize \(f(x)\) using gradient descent. There are several values of \(x\) such that \(f\) is not differentiable at \(x\); if any of our guesses \(x^{(0)}, x^{(1)}, x^{(2)}, \ldots\) ever evaluate to one of these values, we say that gradient descent crashes.
2 pts True or False: \(f(x)\) is convex on the domain \(x \in [-9, 9]\).
Solution
This is false. In order for a function to be convex, it must be the case that we can draw a line segment between any two points on the function and the line segment never passes below the function, but this is not the case for this \(f\). For example, connect \((-3, 1)\) to \((-1, -3)\); the line segment is entirely beneath the function.
4 pts Suppose we choose a learning rate/step size of \(\alpha = 0.1\).
Among the options below, which value of \(x^{(0)}\) will allow gradient descent to converge to the global minimum of \(f(x)\) without crashing?
If multiple values of \(x^{(0)}\) are possible, select the value that converges the quickest (i.e. in the fewest number of iterations).
Solution
When \(x\) is between \(1\) and \(2\), the slope is 4, so with learning rate \(\alpha = 0.1\), gradient descent updates by
Now, let’s check the options:
\(1.4 \to 1.0\), so gradient descent crashes at the nondifferentiable point \(x=1\).
\(1.6 \to 1.2 \to 0.8\), so it reaches the flat global-minimum region without crashing.
\(1.8 \to 1.4 \to 1.0\), so it crashes.
\(1.9 \to 1.5 \to 1.1 \to 0.7\), so it also works, but it takes more iterations than starting at 1.6.
Starting at \(2.0\) crashes immediately, because \(f\) is not differentiable there.
Therefore, the correct choice is \(\boxed{1.6}\).
WN26 MT2 · Problem 7 10 pts
From WN26 MT2
6 pts Suppose \(A\) is a \(4 \times 4\) matrix and \(\vec x \in \mathbb{R}^4\). Furthermore, suppose that the gradient of the function \(f(\vec x) = \vec x^T A \vec x\) is given by
Find one possible matrix \(A\). Your answer should be a \(4 \times 4\) matrix with no variables.
\(A = \_\_\_\_\_\_\)
Solution
Recall that for
the gradient is
We want
One easy way to make this happen is to choose \(A\) to be diagonal and symmetric. Then \(A + A^T = 2A\), so we want
Thus, one possible choice is
4 pts Suppose \(A\) is an \(n \times n\) matrix, \(\vec b \in \mathbb{R}^n\), and that \(g: \mathbb{R}^n \to \mathbb{R}\) is defined by
Which of the following is \(\nabla g(\vec x)\), the gradient of \(g(\vec x)\)?
\(2 A^T \vec b\)
\((\vec b^T A \vec x) A^T \vec b\)
\(2 (\vec b^T A \vec x) \vec b\)
\(2 (\vec b^T A \vec x) A^T \vec b\)
\(2 (\vec b^T A \vec x) A^T \vec x\)
None of the above
Solution
None of the above
Let
Then
The gradient of \(f(\vec x)\) can be computed using the dot product “big three” rule, which tells us that
Applying the chain rule,
WN26 MT2 · Problem 8 11 pts
From WN26 MT2
Let \(\vec x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\). Consider the function
3 pts Fill in the blanks: The set of all vectors \(\vec x^{\ast}\) that minimize \(f(\vec x)\) form a __(i)__ in \(\mathbb{R}^2\). This set __(ii)__ a subspace of \(\mathbb{R}^2\).
Solution
We have
$$ f(\vec x) = (x_1 + x_2 - 4)^2 $$so the minimum value is 0, which happens exactly when
$$ x_1 + x_2 - 4 = 0 \iff x_1 + x_2 = 4 $$The equation
$$ x_1 + x_2 = 4 $$describes a line in \(\mathbb{R}^2\).
This line is not a subspace, because it does not pass through the origin. For example,
$$ \begin{bmatrix} 0 \\\\ 0 \end{bmatrix} $$is not a minimizer. Therefore, this set is not a subspace.
8 pts Suppose we use gradient descent to minimize \(f(\vec x)\) using an initial guess of \(\vec x^{(0)} = \begin{bmatrix} 1 \\ 1 \end{bmatrix}\).
Find the learning rate/step size \(\alpha\) that will cause gradient descent to converge to a global minimum of \(f(\vec x)\) in one iteration, i.e. such that \(\vec x^{(1)}\) is a minimizer of \(f(\vec x)\).
Show your work in the space provided, and write your final answer in the bottom-right corner of the box. Your answer should be a number with no variables.
Solution
First, we need to compute the gradient of \(f(\vec x)\):
At
we have
so
One gradient descent step gives
We want \(\vec x^{(1)}\) to be a minimizer, so it must satisfy
That gives
WN26 Final · Problem 8 9 pts MT2 Redemption
From WN26 Final
Consider the function \(g: \mathbb{R}^3 \to \mathbb{R}\). We’d like to minimize \(g\) using gradient descent.
(6 pts) Suppose two separate runs of gradient descent are started from the same initial guess \(\vec x^{(0)}\), but with different learning rates (step sizes), \(\alpha\).
If \(\alpha = 1/2\), then \(\vec x^{(1)} = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}\), and if \(\alpha = 1/4\), then \(\vec x^{(1)} = \begin{bmatrix} 2 \\ 3 \\ 2 \end{bmatrix}\).
Find \(\nabla g(\vec x^{(0)})\), the gradient of \(g\) at \(\vec x^{(0)}\). Show your work, and write your final answer in the box provided. Your answer should be a vector with no variables.
Solution
Let \(\vec d = \nabla g(\vec x^{(0)})\). The gradient descent update rule is
The two runs give
and
Subtracting the second equation from the first eliminates \(\vec x^{(0)}\):
So
Now let \(\vec x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\), and consider the function \(f: \mathbb{R}^2 \to \mathbb{R}\) defined by
3 pts Suppose
for some \(2 \times 3\) matrix \(M\). Which of the following matrices is \(M\)?
Solution
\(\begin{bmatrix} 4 & 4 & -12 \\ 2 & 6 & -12 \end{bmatrix}\)
We have
Using the chain rule,
We applied the chain rule above by writing \(\left( x_1 + 2x_2 - 6 \right)^2 = (\begin{bmatrix} 1 \\ 2 \end{bmatrix} \cdot \vec x - 6)^2\). If this feels foreign, we can instead take partial derivatives with respect to \(x_1\) and \(x_2\) separately.
Either way, \(\nabla f(\vec x)\) simplifies to
So,
SP26 MT2 · Problem 6 12 pts
From SP26 MT2
Suppose \(A\) is an \(n \times d\) matrix and \(\vec x \in \mathbb{R}^d\). Consider the function \(f: \mathbb{R}^d \to \mathbb{R}\) given by
2 pts True or False: \(f(\vec x)\) is a linear transformation.
Solution
This is false. Recall, a linear transformation must satisfy \(f(c \vec x) = c f(\vec x)\) for any scalar \(c\). But, suppose we pick \(n = d = 1\), and let \(A = [1]\) (here we’re thinking of a \(1 \times 1\) matrix as a scalar). Then, \(f(x)\) is just the absolute value of the scalar \(x\).
But, \(f(-2) = 2\) is not the same as \(-2 f(1) = -2\). So, this \(f(x)\) is not a linear transformation, and thus in general \(f(\vec x) = \lVert A \vec x \rVert\) is not a linear transformation.
Another way to think about why \(f(\vec x)\) is not linear is to use the fact that \(\lVert A \vec x \rVert^2 = \vec x^T A^T A \vec x\):
\(f(\vec x)\) is the square root of a quadratic form, which is not linear.
10 pts Find \(\nabla f(\vec x)\). Assume that \(A \vec x \neq \vec 0\). Show your work, and write your final answer in the bottom-right corner of the box. Your answer should be an expression in terms of \(A\), \(\vec x\), and/or constants. Hint: Start by taking the gradient of \(\lVert A \vec x \rVert^2\), then apply the chain rule.
Solution
As the hint suggests, let’s start by writing
Using the quadratic-form gradient rule,
Now,
The chain rule from Chapter 8.2 states that if \(f(\vec x) = h(g(\vec x))\), where \(h: \mathbb{R} \to \mathbb{R}\) and \(g: \mathbb{R}^d \to \mathbb{R}\) are both differentiable, then \(\nabla f(\vec x) = h’(g(\vec x)) \nabla g(\vec x)\).
Here, \(h(x) = \sqrt{x}\) (so \(h’(x) = \displaystyle \frac{1}{2\sqrt{x}}\)) and \(g(\vec x) = \left|A\vec x\right|^2\), so
SP26 MT2 · Problem 7 15 pts
From SP26 MT2
Let \(\vec x = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\). Consider the function \(f: \mathbb{R}^2 \to \mathbb{R}\) given by
where \(c\) and \(d\) are constants. We’d like to use gradient descent to minimize \(f(\vec x)\). For some values of \(c\) and \(d\), and some initial guess \(\vec x^{(0)}\) and learning rate/step size \(\alpha\), we find that
5 pts Find the value of \(\alpha\). Show your work, and write your final answer in the bottom-right corner of the box. Your answer should be a number with no variables.
Solution
Gradient descent uses the update
Substituting the given values,
Using either component,
5 pts Find the value of \(d\) (not \(c\)). Show your work, and write your final answer in the bottom-right corner of the boxes. Your answer should be a number with no variables.
Solution
The gradient of
is
At \(\vec x^{(1)} = \begin{bmatrix} 4 \\ 1 \end{bmatrix}\), we’re told that
Using the second component (because we’re only asked for \(d\)),
5 pts Your friend claims that gradient descent always converges to a minimum because each iteration moves in the direction of steepest decrease. Based on the information in this problem, is your friend correct? State “yes” or “no”, and briefly explain your reasoning.
Solution
No. From part b), \(d=-1\), so
This function does not have a minimum, because we can make \(f(\vec x)\) arbitrarily negative by making \(|x_2|\) arbitrarily large. So, in this problem, gradient descent cannot converge to a minimum.
SP26 Final · Problem 9 9 pts MT2 Redemption
From SP26 Final
Let \(\vec a \in \mathbb{R}^2\) and let
for all vectors \(\vec x\) such that \(\vec a \cdot \vec x > 0\); if \(\vec a \cdot \vec x \leq 0\), then \(f(\vec x)\) is undefined. Suppose that
3 pts Which of the following could be \(\vec a\)? Select all that apply.
Solution
\(\begin{bmatrix}2\\6\end{bmatrix}\)
Let
Then \(f(\vec{x})=h(g(\vec{x}))\). Using the chain rule from Chapter 8.2,
Now,
so
At \(\vec{x}=\begin{bmatrix}2\\1\end{bmatrix}\), this becomes
Since \(f\) is defined at \(\begin{bmatrix}2\\1\end{bmatrix}\), this must mean that \(\vec a \cdot \vec x\), which is equal to \(2a_1 + a_2\), is positive. Multiplying both sides by this positive denominator gives
This says \(\vec{a}\) must be a positive scalar multiple of \(\begin{bmatrix}1\\3\end{bmatrix}\). Among the answer choices, the vectors with that form are \(\begin{bmatrix}1\\3\end{bmatrix}\) and \(\begin{bmatrix}2\\6\end{bmatrix}\).
Another way to approach this would be to take the equation
from above, and realize the expression on the right is also equal to \(\frac{1}{2a_1+a_2} \begin{bmatrix}a_1\\a_2\end{bmatrix}\), which allows us to set up a system of equations directly for \(a_1\) and \(a_2\):
Both equations say the same thing: \(a_2 = 3a_1\), i.e. that \(a_2\) must be triple \(a_1\), so \(\vec a\) is a scalar multiple of \(\begin{bmatrix}1\\3\end{bmatrix}\). But, don’t forget the added constraint that \(2a_1 + a_2\) must be positive.
4 pts Suppose we use gradient descent to minimize \(f(\vec x)\) using an initial guess of \(\vec x^{(0)} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}\) and a learning rate of \(\alpha = 1/2\). Find \(\vec x^{(1)}\). Show your work, and write your answer in the box provided. Your answer should be a vector with no variables.
Solution
The gradient descent update from Chapter 8.3 is
Here, \(\vec{x}^{(0)}=\begin{bmatrix}2\\1\end{bmatrix}\), \(\alpha=1/2\), and \(\nabla f(\vec{x}^{(0)})=\begin{bmatrix}1/5\\3/5\end{bmatrix}\). So,
2 pts This part is unrelated to the previous parts.
Suppose \(g: \mathbb{R} \to \mathbb{R}\). True or false: if \(g\) has a global minimum and no local maxima, it must be convex.
Solution
This is false. For instance, consider
This function has a global minimum, since \(g(x)\to\infty\) as \(x\to\infty\) and as \(x\to-\infty\). Also,
The derivative only changes sign at \(x=-3/4\), where it changes from negative to positive, so \(g\) has a local minimum and no local maxima. But,
which is negative for some \(x\) values, for instance \(x=-1/4\). So \(g\) is not convex. See Chapter 8.5 for the convexity condition.
