Skip to main content

MATH 345: Linear Algebra and Optimization

Section 3.4 Partial derivatives, gradients, Hessians, and Jacobian matrices

Subsection Partial derivatives

Subsubsection Definition and basic concepts

A partial derivative measures change in one input coordinate while the other input coordinates are held fixed.
Definition 3.4.1. Partial Derivatives.
Let \(f(x,y)\) be a scalar-valued function in two variables. The partial derivative of \(f\) with respect to \(x\) at \((a,b)\) is the scalar quantity
\begin{equation*} f_x(a,b) = \lim_{h \to 0} \frac{f(a+h,b) - f(a,b)}{h}\text{,} \end{equation*}
provided this limit exists. Similarly, the partial derivative of \(f\) with respect to \(y\) at \((a,b)\) is the quantity
\begin{equation*} f_y(a,b) = \lim_{h \to 0} \frac{f(a,b+h) - f(a,b)}{h} \end{equation*}
provided this limit exists.
We compute the partial derivative in \(x\) of an expression precisely by treating the \(y\)-variable as a constant, and differentiating in \(x\text{.}\) Similarly, we compute the partial derivative in \(y\) by treating the \(x\)-variable as a constant.
Note 3.4.2.
There are several notations used for the partial derivative of a function \(f(x,y)\text{,}\) namely, we might write \(f_x(a,b)\) as
\begin{equation*} \partial_x f(a,b) \quad \frac{\partial f}{\partial x}(a,b) \quad (D_x f)(a,b) \quad \text{or} \quad (D_1 f)(a,b)\text{.} \end{equation*}
Similarly, we write \(f_y(a,b)\) as
\begin{equation*} \partial_y f(a,b) \quad \frac{\partial f}{\partial y}(a,b) \quad (D_y f)(a,b) \quad \text{or} \quad (D_2 f)(a,b)\text{.} \end{equation*}
Activity 3.4.1.
Let
\begin{equation*} f(x,y) = x^2 - 3xy + 2y^2 - 4x + 5y - 12 \end{equation*}
(a)
Calculate \(f_x(x,y)\) directly using the definition of the derivative.
Solution.
We must evaluate the limit
\begin{equation*} \lim_{h \to 0} \frac{f(x + h,y) - f(x,y)}{h}\text{.} \end{equation*}
We begin by expanding and simplifying the expression \(f(x + h,y)\text{,}\) that
\begin{align*} f(x+h,y) \amp = (x+h)^2 - 3(x+h)y + 2y^2 - 4(x+h) + 5y - 12\\ \amp = x^2 + 2xh + h^2 - 3xy - 3hy + 2y^2 - 4x - 4h + 5y - 12\\ \amp = x^2 - 3xy + 2y^2 - 4x + 5y - 12 + h(2x - 3y - 4 + h)\\ \amp = f(x,y) + h(2x - 3y - 4 + h)\text{.} \end{align*}
So for \(h \neq 0\text{,}\)
\begin{equation*} \lim_{h \to 0} \frac{f(x + h,y) - f(x,y)}{h} = \lim_{h \to 0} 2x - 3y - 4 + h = 2x - 3y - 4\text{.} \end{equation*}
So
\begin{equation*} f_x(x,y) = 2x - 3y - 4\text{.} \end{equation*}
(b)
Calculate \(f_y(x,y)\) directly using the definition of the derivative.
Solution.
We first calculate that
\begin{align*} f(x,y+h) \amp = x^2 - 3x(y+h) + 2(y+h)^2 - 4x + 5(y+h) - 12\\ \amp = x^2 - 3xy - 3xh + 2y^2 + 4yh + 2h^2 - 4x + 5y + 5h - 12\\ \amp = f(x,y) + h(-3x + 4y + 2h + 5)\text{.} \end{align*}
So
\begin{equation*} \lim_{h \to 0} \frac{f(x,y+h) - f(x,y)}{h} = \lim_{h \to 0} -3x + 4y + 2h + 5 = -3x + 4y + 5\text{.} \end{equation*}
So
\begin{equation*} f_y(x,y) = -3x + 4y + 5\text{.} \end{equation*}
Activity 3.4.2.
For each function \(f(x,y)\text{,}\) find \(f_x(x,y)\) and \(f_y(x,y)\text{.}\)
(a)
\(f(x,y) = 3x^2y+2x-3y\)
Solution.
To find \(f_x(x,y)\text{,}\) treat \(y\) as a constant:
\begin{align*} f_x(x,y) \amp = \frac{\partial}{\partial x}(3x^2y+2x-3y)\\ \amp = 3 \cdot 2xy + 2 - 0\\ \amp = 6xy + 2\text{.} \end{align*}
To find \(f_y(x,y)\text{,}\) treat \(x\) as a constant:
\begin{align*} f_y(x,y) \amp = \frac{\partial}{\partial y}(3x^2y+2x-3y)\\ \amp = 3x^2 \cdot 1 + 0 - 3\\ \amp = 3x^2 - 3\text{.} \end{align*}
(b)
\(f(x,y) = x\sin y + y\sin x\)
Solution.
Treating \(y\) as a constant, we find that
\begin{align*} f_x(x,y) \amp = \frac{\partial}{\partial x}(x\sin y + y\sin x)\\ \amp = 1 \cdot \sin y + y \cdot \cos x\\ \amp = \sin y + y\cos x\text{.} \end{align*}
Treating \(x\) as a constant, we find that
\begin{align*} f_y(x,y) \amp = \frac{\partial}{\partial y}(x\sin y + y\sin x)\\ \amp = x \cdot \cos y + 1 \cdot \sin x\\ \amp = x\cos y + \sin x\text{.} \end{align*}
(c)
\(f(x,y) = x^2e^{xy}\text{.}\)
Solution.
To find \(f_x(x,y)\text{,}\) treat \(y\) as a constant and use the product and chain rules:
\begin{align*} f_x(x,y) \amp = \frac{\partial}{\partial x}(x^2e^{xy})\\ \amp = \frac{\partial}{\partial x}(x^2) \cdot e^{xy} + x^2 \cdot \frac{\partial}{\partial x}(e^{xy})\\ \amp = 2x \cdot e^{xy} + x^2 \cdot e^{xy} \cdot \frac{\partial}{\partial x}(xy)\\ \amp = 2x \cdot e^{xy} + x^2 \cdot e^{xy} \cdot y\\ \amp = 2xe^{xy} + x^2ye^{xy}\\ \amp = xe^{xy}(2 + xy)\text{.} \end{align*}
To find \(f_y(x,y)\text{,}\) treat \(x\) as a constant:
\begin{align*} f_y(x,y) \amp = \frac{\partial}{\partial y}(x^2e^{xy})\\ \amp = x^2 \cdot \frac{\partial}{\partial y}(e^{xy})\\ \amp = x^2 \cdot e^{xy} \cdot \frac{\partial}{\partial y}(xy)\\ \amp = x^2 \cdot e^{xy} \cdot x\\ \amp = x^3e^{xy}\text{.} \end{align*}

Subsubsection Geometric interpretation

Definition 3.4.3. The Slice of a Function.
Given a function \(f(x,y)\) and \(b \in \R\text{,}\) the slice of the function \(f\) in the plane \(y = b\) is the function \(g: \R \to \R\) given by \(g(x) = f(x,b)\text{.}\) Similarly, for \(x \in \R\) the slice of \(f\) in the plane \(x = a\) is the function \(g: \R \to \R\) given by \(g(y) = f(a,y)\text{.}\)
Geometrically, the slice of a function \(f\) in the plane \(y = b\) corresponding to intersecting the surface given by the equation \(z = f(x,y)\) with the plane \(y = b\text{,}\) creating a curve in this plane.
Activity 3.4.3.
Sketch the slices of the function \(f(x,y) = \sin(x + y^2)\) in the plane \(y = b\text{.}\)
Solution.
The slice in the plane \(y = b\) is the function
\begin{equation*} g(x) = f(x,b) = \sin(x + b^2)\text{.} \end{equation*}
This slice is a sine function with a phase shift of \(b^2\text{.}\) See FigureΒ 3.4.4 for a sketch of these slices.
A surface z equals sin of x plus y squared with several fixed-y slice curves.
The figure shows a translucent blue surface for \(z = \sin(x+y^2)\) over \(0 \leq y \leq 1\text{.}\) Five colored curves lie on the surface at fixed values \(y=0\text{,}\) \(y=0.25\text{,}\) \(y=0.5\text{,}\) \(y=0.75\text{,}\) and \(y=1\text{,}\) illustrating how the slice \(z=\sin(x+b^2)\) shifts as \(b\) changes.
Figure 3.4.4. The graph of \(f(x,y) = \sin(x + y^2)\) showing slices at different values of \(y\text{.}\) Each curve represents the function \(f(x,y)\) for a fixed value of \(y\text{.}\) Adapted from: Stanford’s MATH 51 textbook
Activity 3.4.4.
Let \(f(x,y) = 16 - x^2 - y^2\text{.}\) Find \(f_x(1,2)\) and \(f_y(1,2)\) and interpret these numbers as slopes of a certain curve.
Solution.
We calculate that
\begin{align*} f_x(x,y) \amp = \frac{\partial}{\partial x}(16 - x^2 - y^2)\\ \amp = 0 - 2x - 0\\ \amp = -2x\text{.} \end{align*}
So
\begin{equation*} f_x(1,2) = -2(1) = -2\text{.} \end{equation*}
This is the slope of the curve in the \(xz\) plane obtained by intersecting the surface \(z = 16 - x^2 - y^2\) with the plane defined by the equation \(y = 2\text{,}\) at the point \((1,2,11)\text{.}\) That is, the tangent line of the curve at this point is given by \(z - 11 = -2 ( x - 1 )\text{.}\)
We calculate that
\begin{align*} f_y(x,y) \amp = \frac{\partial}{\partial y}(16 - x^2 - y^2)\\ \amp = 0 - 0 - 2y\\ \amp = -2y\text{.} \end{align*}
So
\begin{equation*} f_y(1,2) = -2(2) = -4\text{.} \end{equation*}
This is the slope of the curve in the \(yz\) plane obtained by intersecting the surface \(z = 16 - x^2 - y^2\) with the plane defined by the equation \(x = 1\text{,}\) at the point \((1,2,11)\text{.}\) That is, the tangent line of the curve at this point is given by \(z - 11 = -4 ( y - 2 )\text{.}\)
Activity 3.4.5.
Consider the contour plot shown in FigureΒ 3.4.6 for a function \(F\) with contour lines at increments of \(0.2\text{.}\) In particular, consider the curve obtained from the slice \(y = 0\text{,}\) indicated by the red line in FigureΒ 3.4.6. By interpreting the contour plot, what can we say about the slopes of this curve, or equivalently, the values of \(F_x\) on this line?
A contour plot with level increments of 0.2 and the line y equals 0 highlighted.
The contour plot shows a synthetic function with labeled level curves spaced by \(0.2\text{.}\) A thick red horizontal line marks \(y=0\text{,}\) so the intersections of that line with the contour curves can be compared with the one-variable slice along \(y=0\text{.}\)
Figure 3.4.6. A contour plot for a function with increments of \(0.2\text{.}\) The line \(y = 0\) is indicated in red. Adapted from: Stanford’s MATH 51 textbook
Solution.
Here is some of the information we can read from the contour plot:
  • Between \(x = -1\) and \(x = 0\text{,}\) the contour values increase (from about \(0.2\) to \(1\)), indicating \(F_x > 0\) in this region (the function \(F\) is increasing).
  • Near \(x = 1\text{,}\) the contour lines are very close together, and the contour values decrease, indicating the \(F_x \lt 0\text{,}\) and that the magnitude of \(F_x\) is large (the curve slopes steeply downward).
  • Between \(x = 1.5\) and \(x = 3\text{,}\) the contour values increase, indicating \(F_x > 0\text{.}\) (the function \(F\) is increasing).
See FigureΒ 3.4.7 for a graph depicting the curve, to check what we have deduced is correct.
A red one-variable slice curve F of x comma 0 with dashed vertical guide lines.
The graph shows the slice \(F(x,0)\) as a red curve. Black points mark where the slice reaches contour levels in increments of \(0.2\text{,}\) and gray dashed vertical lines run from the \(x\)-axis up to those points.
Figure 3.4.7. The slice of the function \(F(x,y)\) where \(y = 0\text{.}\) The dashed lines correspond to increments of \(0.2\) in the \(x\)-axis. Adapted from: Stanford’s MATH 51 textbook
Activity 3.4.6.
Consider FigureΒ 3.4.8, which is the same contour plot as in FigureΒ 3.4.6, but with the vertical line \(x = 2.25\) indicated instead. As in ActivityΒ 3.4.5, read off the behaviour of the partial derivatives \(F_y\) from the contour plot.
A contour plot with level increments of 0.2 and the line x equals 2.25 highlighted.
The contour plot shows the same synthetic function as the preceding contour figure, with labeled level curves spaced by \(0.2\text{.}\) A thick red vertical line marks \(x=2.25\text{,}\) so changes in contour values along this vertical slice can be read from bottom to top.
Figure 3.4.8. A contour plot with increments of \(0.2\text{,}\) with the vertical line \(x = 2.25\) highlighted in red. Adapted from: Stanford’s MATH 51 textbook
Solution.
Here is some information that can be deduced from the contour plot:
  • The contour values are always decreasing as we increase \(y\) along the red line, so that \(F_y \lt 0\) on this line.
  • The contour lines are closest together near \(y = -1\text{,}\) so \(F_y(2.25,y)\) will have largest magnitude on the line near \(y = -1\text{.}\)
Generally, the spacing of contour lines corresponds to the magnitude of partial derivatives, and the sign of the partial derivatives corresponds to whether the function increases or decreasing in that direction.
Activity 3.4.7.
Consider the function \(f(x,y) = x(y^2 + 1)\text{,}\) whose contour plot is indicated in FigureΒ 3.4.9. Five points are marked on the plot: \(P = (0,0)\text{,}\) \(Q = (3/2,0)\text{,}\) \(R = (7/2,0)\text{,}\) \(S = (2,1)\text{,}\) and \(T = (2,-1)\text{.}\) For each of these five points, determine from the contour plot whether \(f_x\) is positive, negative, or zero, and whether \(f_y\) is positive, negative, or zero. Then calculate these derivatives exactly and check whether your observations were correct.
Contour plot of x times y squared plus one with five labeled points.
The contour plot shows level curves of \(f(x,y)=x(y^2+1)\) for levels from \(0\) through \(10\) in steps of \(1\text{.}\) The level curves are symmetric across the \(x\)-axis and bend to the right as \(|y|\) increases. The marked points are \(P=(0,0)\text{,}\) \(Q=(3/2,0)\text{,}\) \(R=(7/2,0)\text{,}\) \(S=(2,1)\text{,}\) and \(T=(2,-1)\text{.}\)
Figure 3.4.9. Contour plot for \(f(x,y) = x(y^2 + 1)\) with increments of \(1\text{,}\) and five points \(P\text{,}\) \(Q\text{,}\) \(R\text{,}\) \(S\text{,}\) and \(T\) indicated. Adapted from: Stanford’s MATH 51 textbook
Solution.
At all five points, \(f_x > 0\) because the contour values increase as increase values of \(x\text{.}\) The contour lines around points \(S\) and \(T\) are more tightly packed than around \(P\text{,}\) \(Q\text{,}\) and \(R\text{,}\) indicating that \(f_x\) has larger magnitude at \(S\) and \(T\) than at \(P\text{,}\) \(Q\text{,}\) and \(R\text{.}\)
At the point \(P\text{,}\) \(f_y = 0\) since the contour line passing through \(P\) is a straight vertical line. It is not possible to determine the sign of \(f_y\) at the points \(Q\) and \(R\text{,}\) but we know the value of \(f_y\) must be small since the contour lines are more spread out than anywhere else in the plot. At the point \(S\text{,}\) \(f_y > 0\text{,}\) since the contour values increase as we increase in \(y\) values. At the point \(T\text{,}\) \(f_y \lt 0\) since the contour values decrease.
We now verify these observations by computing partial derivatives. We check that
\begin{equation*} \frac{\partial f}{\partial x} = y^2 + 1 \quad\text{and}\quad \frac{\partial f}{\partial y} = 2xy\text{.} \end{equation*}
So
  • \(f_x(P) = f_x(0,0) = 1\) and \(f_y(P) = f_y(0,0) = 0\text{.}\)
  • \(f_x(Q) = f_x(3/2,0) = 1\) and \(f_y(Q) = f_y(3/2,0) = 0\text{.}\)
  • \(f_x(R) = f_x(7/2,0) = 1\) and \(f_y(R) = f_y(7/2,0) = 0\text{.}\)
  • \(f_x(S) = f_x(2,1) = 2\) and \(f_y(S) = f_y(2,1) = 4\text{.}\)
  • \(f_x(T) = f_x(2,-1) = 2\) and \(f_y(T) = f_y(2,-1) = -4\text{.}\)

Subsubsection Partial derivatives with more variables

The concept of partial derivatives extends naturally to functions of more than two variables.
Definition 3.4.10.
For a function \(f(\mathbf{x}) = f(x_1, \dots, x_n)\) of \(n\) variables, the partial derivative with respect to \(x_i\) is defined as
\begin{equation*} f_{x_i}(\mathbf{x}) = \lim_{h \to 0} \frac{f(x_1, \dots, x_i+h, \dots, x_n) - f(x_1, \ldots, x_n)}{h} \end{equation*}
provided this limit exists. Using vector notation, we can write this definition more cleanly, by writing
\begin{equation*} f_{x_i}(\mathbf{x}) = \lim_{h \to 0} \frac{f(\mathbf{x} + h \mathbf{e}_i) - f(\mathbf{x})}{h}\text{,} \end{equation*}
where \(\mathbf{e}_1,\dots,\mathbf{e}_n\) are the standard basis vectors (recall DefinitionΒ 1.3.8). This partial derivative is also written as
\begin{equation*} \frac{\partial f}{\partial x_i} \quad \partial_{x_i} f \quad\text{or}\quad (D_i f)(\mathbf{x})\text{.} \end{equation*}
If the variables \(x_1,\dots,x_n\) are denoted using different symbols, these symbols might also be used to denote the partial derivatives instead. For instance, in \(\R^3\text{,}\) we might write a function as \(f(x,y,z)\text{,}\) and then the three partial derivatives of \(f\) may be denoted using any of the following four notations:
  • \(\frac{\partial f}{\partial x}\text{,}\) \(\frac{\partial f}{\partial y}\text{,}\) and \(\frac{\partial f}{\partial z}\text{.}\)
  • \(f_x, f_y\text{,}\) and \(f_z\text{.}\)
  • \(\partial_x f, \partial_y f\) and \(\partial_z f\text{.}\)
  • \(D_1 f\text{,}\) \(D_2 f\text{,}\) and \(D_3 f\text{.}\)
As for functions of two variables, we can calculate these derivatives by treating all variables but that we are taking the partial derivative of as constants.
Activity 3.4.8.
If \(f(x,y,z) = 5x^2y^2z^3\text{,}\) find \(f_x\text{,}\) \(f_y\text{,}\) and \(f_z\text{.}\)
Solution.
To find \(f_x\text{,}\) treat \(y\) and \(z\) as constants:
\begin{align*} f_x(x,y,z) \amp = \frac{\partial}{\partial x}(5x^2y^2z^3)\\ \amp = 5(2x)y^2z^3\\ \amp = 10xy^2z^3 \end{align*}
To find \(f_y\text{,}\) treat \(x\) and \(z\) as constants:
\begin{align*} f_y(x,y,z) \amp = \frac{\partial}{\partial y}(5x^2y^2z^3)\\ \amp = 5x^2 (2y)z^3\\ \amp = 10x^2yz^3 \end{align*}
To find \(f_z\text{,}\) treat \(x\) and \(y\) as constants:
\begin{align*} f_z(x,y,z) \amp = \frac{\partial}{\partial z}(5x^2y^2z^3)\\ \amp = 5x^2y^2(3z^2)\\ \amp = 15x^2y^2z^2 \end{align*}
Activity 3.4.9.
Find \(f_x\text{,}\) \(f_y\text{,}\) and \(f_z\) where \(f(x,y,z) = xy + yz + xz\text{.}\)
Solution.
\begin{align*} f_x(x,y,z) \amp = \frac{\partial}{\partial x}(xy + yz + xz)\\ \amp = y + 0 + z\\ \amp = y + z \end{align*}
\begin{align*} f_y(x,y,z) \amp = \frac{\partial}{\partial y}(xy + yz + xz)\\ \amp = x + z + 0\\ \amp = x + z \end{align*}
\begin{align*} f_z(x,y,z) \amp = \frac{\partial}{\partial z}(xy + yz + xz)\\ \amp = 0 + y + x\\ \amp = x + y \end{align*}
Activity 3.4.10.
Find \(f_x\) and \(f_y\) where \(z = f(x,y) = x\ln y + ye^x\text{.}\)
Solution.
\begin{align*} f_x(x,y) \amp = \frac{\partial}{\partial x}(x\ln y + ye^x)\\ \amp = \ln y + ye^x\\ \amp = \ln y + ye^x \end{align*}
\begin{align*} f_y(x,y) \amp = \frac{\partial}{\partial y}(x\ln y + ye^x)\\ \amp = x \cdot \frac{1}{y} + 1 \cdot e^x\\ \amp = \frac{x}{y} + e^x \end{align*}

Subsubsection Higher-order partial derivatives

Given a scalar-valued function \(f\text{,}\) the partial derivatives of \(f\) (where defined) are also scalar-valued functions, so we can consider partial derivatives of that function as well, which leads to higher order partial derivatives.
Definition 3.4.11.
If \(f\) is a function of two variables, then the second-order partial derivatives of \(f\) are defined as:
  • The derivative \(f_{xx}\) or \(\frac{\partial^2 f}{\partial x^2}\text{,}\) obtained by taking the partial derivative of \(f\) twice in the \(x\) variable.
  • The derivative \(f_{yx}\) or \(\frac{\partial^2 f}{\partial y \partial x}\text{,}\) obtained by first differentiating \(f\) in the \(x\) variable, and then differentiating \(f\) in the \(y\) variable.
  • The derivative \(f_{xy}\text{,}\) or \(\frac{\partial^2 f}{\partial x \partial y}\text{,}\) obtained by first differentiating \(f\) in the \(y\) variable, and then differentiating \(f\) in the \(x\) variable.
  • The derivative \(f_{yy}\text{,}\) or \(\frac{\partial^2 f}{\partial y^2}\text{,}\) obtained by differentiating \(f\) twice in the \(y\) variable.
Similarly, for a function \(f(x_1,\dots,x_n)\text{,}\) the higher derivatives of \(f\) are defined as \(f_{x_i x_j} = \frac{\partial^2 f}{\partial x_i \partial x_j}\) for \(1 \leq i,j \leq n\text{,}\) obtained by first differentiating \(f\) in the variable \(x_j\text{,}\) and then differentiating \(f\) in the \(x_i\) variable.
Activity 3.4.11.
In this activity we compute all four partial derivatives of the function \(f(x,y) = x \ln y + y e^x\text{.}\)
(a)
First compute \(f_x\) and \(f_y\text{.}\)
Solution.
We calculate that
\begin{equation*} f_x(x,y) = \ln y + y e^x \end{equation*}
and
\begin{equation*} f_y(x,y) = x/y + e^x\text{.} \end{equation*}
(b)
Next, compute \(f_{xx}\) and \(f_{yy}\text{.}\)
Solution.
We calculate \(f_{xx}\) by differentiating the function \(f_x(x,y) = \ln y + y e^x\) in the \(x\)-variable, i.e.,
\begin{equation*} f_{xx}(x,y) = y e^x\text{.} \end{equation*}
Similarly, we calculate \(f_{yy}\) by differentiating the function \(f_y(x,y) = x/y + e^x\) in the \(y\)-variable, i.e.,
\begin{equation*} f_{yy}(x,y) = -x/y^2 \end{equation*}
(c)
Now compute \(f_{xy}\) and \(f_{yx}\text{.}\)
Solution.
We compute \(f_{xy}\) by differentiating the function \(f_y = x/y + e^x\) in the \(x\)-variable, i.e., so that
\begin{equation*} f_{xy}(x,y) = 1/y + e^x\text{.} \end{equation*}
We compute \(f_{yx}\) by differentiating the function \(f_x = \ln y + y e^x\) in the \(y\)-variable, i.e., so that
\begin{equation*} f_{yx} = 1/y + e^x\text{.} \end{equation*}
Notice that both functions are continuous, and equal to one another, as guaranteed by TheoremΒ 3.4.12.
Note 3.4.13.
For most functions \(f\) encountered in practice, the second-order partial derivatives are continuous where defined, and so TheoremΒ 3.4.12 applies. However, there are functions for which mixed partial derivatives are not equal to one another.
Activity 3.4.12.
Find all four second partial derivatives of the function
\begin{equation*} f(x,y) = \ln(x^3 + y^2)\text{.} \end{equation*}
Solution.
We begin by calculating \(f_x\) and \(f_y\) using the chain rule, i.e., calculating that
\begin{equation*} f_x(x,y) = \frac{1}{x^3 + y^2} (3x^2) = \frac{3x^2}{x^3 + y^2} \end{equation*}
and
\begin{equation*} f_y(x,y) = \frac{1}{x^3 + y^2} (2y) = \frac{2y}{x^3 + y^2}\text{.} \end{equation*}
The quotient rule then tells us that
\begin{align*} f_{xx} \amp = (f_x)_x\\ \amp = \frac{(x^3 + y^2) (6x) - (3x^2) ( 3x^2 )}{(x^3 + y^2)^2}\\ \amp = \frac{6x^4 + 6xy^2 - 9x^4}{(x^3 + y^2)^2} \end{align*}
that
\begin{align*} f_{yy} \amp = (f_y)_y\\ \amp = \frac{(x^3 + y^2) 2 - (2y)(2y)}{(x^3 + y^2)^2}\\ \amp = \frac{2x^3 - 2y^2}{(x^3 + y^2)^2} \end{align*}
that
\begin{align*} f_{xy} \amp = (f_y)_x\\ \amp = \frac{(x^3 + y^2) (0) - (2y)(3x^2)}{(x^3 + y^2)^2}\\ \amp = \frac{-6x^2y}{(x^3 + y^2)^2} \end{align*}
and that
\begin{align*} f_{yx} \amp = (f_x)_y\\ \amp = \frac{(x^3 + y^2)(0) - (3x^2)(2y)}{(x^3 + y^2)^2}\\ \amp = \frac{-6x^2 y}{(x^3 + y^2)^2}\text{.} \end{align*}

Subsubsection Gradients and Hessians

The gradient collects first partial derivatives of a scalar-valued function.
Definition 3.4.14. Gradient.
Let \(f\) be a scalar-valued function of \(n\) variables. At a point \(\mathbf{x}\) where all first partial derivatives of \(f\) exist, the gradient of \(f\) is the vector
\begin{equation*} (\nabla f)(\mathbf{x}) = \begin{bmatrix} D_1 f(\mathbf{x}) \\ \vdots \\ D_n f(\mathbf{x}) \end{bmatrix}\text{.} \end{equation*}
When these vectors are defined throughout a domain, they form a vector-valued function \(\nabla f\text{.}\)
Activity 3.4.13.
Let \(f(x,y) = \sin(x + y^2)\text{.}\) Find the gradient of \(f\text{.}\)
Solution.
We begin by computing the partial derivatives of \(f\text{,}\) that
\begin{equation*} f_x(x,y) = \cos(x + y^2) \end{equation*}
and
\begin{equation*} f_y(x,y) = \cos(x + y^2)(2y) = 2y \cos(x + y^2)\text{.} \end{equation*}
So
\begin{equation*} \nabla f(x,y) = \begin{bmatrix} \cos(x + y^2) \\ 2y \cos(x + y^2) \end{bmatrix}\text{.} \end{equation*}
Activity 3.4.14.
Let \(f(x,y) = x^2 + xy + y^2\text{.}\) Compute \(\nabla f(1,2)\text{.}\)
Solution.
We compute that
\begin{equation*} f_x(x,y) = 2x + y \end{equation*}
and
\begin{equation*} f_y(x,y) = x + 2y\text{.} \end{equation*}
So
\begin{equation*} \nabla f(x,y) = \begin{bmatrix} 2x + y \\ x + 2y \end{bmatrix} \end{equation*}
and in particular,
\begin{equation*} \nabla f(1,2) = \begin{bmatrix} 2(1) + (2) \\ (1) + 2(2) \end{bmatrix} = \begin{bmatrix} 4 \\ 5 \end{bmatrix}\text{.} \end{equation*}
An important property of the gradient of a function at a point is that it is a vector that is perpendicular to the level curves of the function.
See FigureΒ 3.4.16 for a graphical example of TheoremΒ 3.4.15.
Contour plot of xy minus x with three gradient vectors perpendicular to level curves.
The plot shows level curves of \(f(x,y)=xy-x\) in the first quadrant and slightly below the \(x\)-axis. Three labeled points appear on different level curves: \(\mathbf{a}=(1,3)\text{,}\) \(\mathbf{b}=(2,2)\text{,}\) and \(\mathbf{c}=(4,3/2)\text{.}\) A red arrow begins at each point and points in the direction of the gradient \(\nabla f=(y-1,x)\text{,}\) crossing the nearby contour lines at right angles.
Figure 3.4.16. A contour plot of the function \(f(x,y) = xy - x\text{,}\) with the gradient vectors at three points \(\mathbf{a} = (1,3)\text{,}\) \(\mathbf{b} = (2,2)\text{,}\) and \(\mathbf{c} = (4,3/2)\text{.}\) Adapted from: Stanford’s MATH 51 textbook
The Hessian collects second partial derivatives.
Definition 3.4.17.
Let \(f\) be a scalar-valued function of \(n\) variables, and suppose the second partial derivatives of \(f\) exist at a point \(\mathbf{x}\text{.}\) The Hessian matrix of \(f\) at \(\mathbf{x}\) is the \(n \times n\) matrix of second partial derivatives:
\begin{equation*} H_f(\mathbf{x}) = \begin{bmatrix} \frac{\partial^2 f}{\partial x_1^2}(\mathbf{x}) \amp \frac{\partial^2 f}{\partial x_1 \partial x_2}(\mathbf{x}) \amp \cdots \amp \frac{\partial^2 f}{\partial x_1 \partial x_n}(\mathbf{x}) \\ \frac{\partial^2 f}{\partial x_2 \partial x_1}(\mathbf{x}) \amp \frac{\partial^2 f}{\partial x_2^2}(\mathbf{x}) \amp \cdots \amp \frac{\partial^2 f}{\partial x_2 \partial x_n}(\mathbf{x}) \\ \vdots \amp \vdots \amp \ddots \amp \vdots \\ \frac{\partial^2 f}{\partial x_n \partial x_1}(\mathbf{x}) \amp \frac{\partial^2 f}{\partial x_n \partial x_2}(\mathbf{x}) \amp \cdots \amp \frac{\partial^2 f}{\partial x_n^2}(\mathbf{x}) \end{bmatrix} \end{equation*}
That is, \(H_f(\mathbf{x})\) is the matrix whose \((i,j)\)-entry is the second derivative \(\frac{\partial^2 f}{\partial x_i \partial x_j}\) obtained by first differentiating in the \(x_j\) variable, and then the \(x_i\) variable. When the relevant mixed second partial derivatives are continuous on a ball around \(\mathbf{x}\text{,}\) Clairaut’s Theorem implies that the Hessian is symmetric at \(\mathbf{x}\text{.}\)
In particular, the Hessian of a scalar-valued function of two variables can be written
\begin{equation*} H_f = \begin{bmatrix} \frac{\partial^2 f}{\partial x^2} \amp \frac{\partial^2 f}{\partial x \partial y} \\ \frac{\partial^2 f}{\partial y \partial x} \amp \frac{\partial^2 f}{\partial y^2} \end{bmatrix} = \begin{bmatrix} f_{xx} \amp f_{xy} \\ f_{yx} \amp f_{yy} \end{bmatrix}\text{.} \end{equation*}
Activity 3.4.15.
Find the Hessian matrix for the function
\begin{equation*} f(x,y) = \sin(x + y^2) \end{equation*}
at a general point \((x,y)\text{.}\)
Solution.
We start by computing the first and second partial derivatives of \(f\text{.}\) In ActivityΒ 3.4.13 we computed that
\begin{equation*} f_x(x,y) = \cos(x + y^2) \quad\text{and}\quad f_y(x,y) = 2y \cos(x + y^2)\text{.} \end{equation*}
We then calculate that
\begin{align*} f_{xx} \amp = \frac{\partial}{\partial x} \{ f_x \}\\ \amp = - \sin(x + y^2)\text{,} \end{align*}
that
\begin{align*} f_{yy} \amp = \frac{\partial}{\partial y} \{ f_y \}\\ \amp = \frac{\partial}{\partial y} \{ 2y \cos(x + y^2) \}\\ \amp = 2 \cos(x + y^2) - 2y \sin(x + y^2) (2y)\\ \amp = 2 \cos(x + y^2) - 4y^2 \sin(x + y^2)\text{,} \end{align*}
that
\begin{align*} f_{xy} \amp = \frac{\partial}{\partial x} \{ f_y \}\\ \amp = \frac{\partial}{\partial x} \{ 2y \cos(x + y^2) \}\\ \amp = -2y \sin(x + y^2)\text{,} \end{align*}
and that
\begin{align*} f_{yx} \amp = \frac{\partial}{\partial y} \{ f_x \}\\ \amp = \frac{\partial}{\partial y} \{ \cos(x + y^2) \}\\ \amp = - \sin(x + y^2)(2y)\\ \amp = -2y \sin(x + y^2)\text{.} \end{align*}
Thus
\begin{align*} H_f(x,y) \amp = \begin{bmatrix} f_{xx} \amp f_{xy} \\ f_{yx} \amp f_{yy} \end{bmatrix}\\ \amp = \begin{bmatrix} - \sin(x + y^2) \amp - 2y \sin(x + y^2) \\ -2y \sin(x + y^2) \amp 2 \cos(x + y^2) - 4y^2\sin(x + y^2) \end{bmatrix}\text{.} \end{align*}
Activity 3.4.16.
Find the Hessian matrix of the function
\begin{equation*} f(x,y) = x^2 + xy + y^2 \end{equation*}
at a general point \((x,y)\)
Solution.
We compute that
\begin{equation*} f_{xx} = \frac{\partial}{\partial x} \{ 2x + y \} = 2, \end{equation*}
that
\begin{equation*} f_{xy} = \frac{\partial}{\partial x} \{ x + 2y \} = 1\text{,} \end{equation*}
that
\begin{equation*} f_{yx} = \frac{\partial}{\partial y} \{ 2x + y \} = 1\text{,} \end{equation*}
and that
\begin{equation*} f_{yy} = \frac{\partial}{\partial y} \{ x + 2y \} = 2\text{.} \end{equation*}
So
\begin{equation*} H_f(x,y) = \begin{bmatrix} f_{xx} \amp f_{xy} \\ f_{yx} \amp f_{yy} \end{bmatrix} = \begin{bmatrix} 2 \amp 1 \\ 1 \amp 2 \end{bmatrix}\text{.} \end{equation*}
Activity 3.4.17.
Let \(f(x,y,z) = xy + yz + xz\text{.}\) Compute its gradient \(\nabla f\) and Hessian \(H_f\) at a general point \((x,y,z)\text{.}\)
Solution.
We begin by computing the gradient. We calculate that
\begin{equation*} f_x(x,y,z) = y + 0 + z\text{,} \end{equation*}
that
\begin{equation*} f_y(x,y,z) = x + z + 0\text{,} \end{equation*}
and that
\begin{equation*} f_z(x,y,z) = 0 + y + x\text{.} \end{equation*}
So
\begin{equation*} \nabla f(x,y,z) = \begin{bmatrix} y + z \\ x + z \\ y + x \end{bmatrix}\text{.} \end{equation*}
Next, we compute the second derivatives of \(f\text{.}\) We compute that \(f_{xx} = f_{yy} = f_{zz} = 0\text{,}\) and that \(f_{xy} = f_{xz} = f_{yx} = f_{yz} = f_{zx} = f_{zy} = 1\text{.}\) So
\begin{equation*} H_f(x,y,z) = \begin{bmatrix} 0 \amp 1 \amp 1 \\ 1 \amp 0 \amp 1 \\ 1 \amp 1 \amp 0 \end{bmatrix}\text{.} \end{equation*}

Subsubsection Jacobian matrices

For vector-valued maps, the Jacobian matrix collects the partial derivatives of all component functions.
The rows correspond to component functions. The columns describe how the output changes when one input coordinate changes.
Definition 3.4.18. Jacobian matrix.
For a vector-valued map \(F: \R^n \to \R^m\) given by
\begin{equation*} F(\mathbf{x}) = \begin{bmatrix} F_1(\mathbf{x}) \\ F_2(\mathbf{x}) \\ \vdots \\ F_m(\mathbf{x}) \end{bmatrix} \end{equation*}
where \(\mathbf{x} = (x_1, x_2, \ldots, x_n)\text{,}\) the Jacobian matrix of \(F\) is the \(m \times n\) matrix:
\begin{equation*} J_F(\mathbf{x}) = \begin{bmatrix} \frac{\partial F_1}{\partial x_1} \amp \frac{\partial F_1}{\partial x_2} \amp \ldots \amp \frac{\partial F_1}{\partial x_n} \\ \frac{\partial F_2}{\partial x_1} \amp \frac{\partial F_2}{\partial x_2} \amp \ldots \amp \frac{\partial F_2}{\partial x_n} \\ \vdots \amp \vdots \amp \ddots \amp \vdots \\ \frac{\partial F_m}{\partial x_1} \amp \frac{\partial F_m}{\partial x_2} \amp \ldots \amp \frac{\partial F_m}{\partial x_n} \end{bmatrix} \end{equation*}
The Jacobian matrix generalizes the concept of the derivative to a vector-valued map of multiple variables. It provides a compact representation of all first-order partial derivatives of a function.
Activity 3.4.18.
Find the Jacobian matrix of \(f(x,y,z) = xy + yz + xz\text{.}\)
Solution.
For a scalar-valued function \(f: \R^n \to \R\text{,}\) the Jacobian matrix is the transpose of the gradient, i.e., \(J_f = (\nabla f)^T\text{.}\) So
\begin{equation*} J_f = (\nabla f)^T = \begin{bmatrix} y + z \amp x + z \amp x + y \end{bmatrix}\text{.} \end{equation*}
Activity 3.4.19.
Compute the Jacobian matrix of \(F(x,y) = ( x^2 - y^2, 2xy, x+y )\text{.}\)
Solution.
We compute that
\begin{align*} J_F \amp = \begin{bmatrix} D_1 F_1 \amp D_2 F_1 \\ D_1 F_2 \amp D_2 F_2 \\ D_1 F_3 \amp D_2 F_3 \end{bmatrix}\\ \amp = \begin{bmatrix} 2x \amp -2y \\ 2y \amp 2x \\ 1 \amp 1 \end{bmatrix}\text{.} \end{align*}
Activity 3.4.20.
Compute the Jacobian matrix of the gradient function \(\nabla f(x,y)\) for \(f(x,y) = x^2 + xy + y^2\text{.}\)
Solution.
First, let’s compute the gradient of \(f(x,y) = x^2 + xy + y^2\text{:}\)
\begin{align*} \frac{\partial f}{\partial x} \amp= 2x + y\\ \frac{\partial f}{\partial y} \amp= x + 2y \end{align*}
So \(\nabla f(x,y) = \begin{bmatrix} 2x + y \\ x + 2y \end{bmatrix}\text{.}\) The Jacobian matrix of the gradient is
\begin{align*} J_{\nabla f} \amp = \begin{bmatrix} D_1 (\nabla f)_1 \amp D_2 (\nabla f)_1 \\ D_1 (\nabla f)_2 \amp D_2 (\nabla f)_2 \end{bmatrix}\\ \amp = \begin{bmatrix} D_1 \{ 2x + y \} \amp D_2 \{ 2x + y \} \\ D_1 \{ x + 2y \} \amp D_2 \{ x + 2y \} \end{bmatrix}\\ \amp = \begin{bmatrix} 2 \amp 1 \\ 1 \amp 2 \end{bmatrix}\text{.} \end{align*}
Note that this is the Hessian of \(f\) (recall DefinitionΒ 3.4.17).