Directional derivatives and the gradient
Imagine you are hiking on a hilly landscape described by a function of two variables \(z = f(x, y)\). If you stand at a specific point and decide to walk, your altitude will change at a rate that depends entirely on the direction you choose. In single variable calculus, you only had two directions to worry about: left and right along the x-axis. Now, you can point yourself in any compass direction in the xy-plane.
To measure this, we fix a unit vector \(u = (u_1, u_2)\) in the xy-plane that tells us which way we are walking. The directional derivative tells us the instantaneous rate of change of our altitude as we step away from a point in the direction of \(u\).
Let \(f(x, y)\) be a differentiable function at the point \((x_0, y_0)\), and let \(u = (u_1, u_2)\) be a unit vector so that \(u_1^2 + u_2^2 = 1\). The directional derivative of \(f\) in the direction of \(u\), denoted \(D_u f(x_0, y_0)\), is the limit
\[D_u f(x_0, y_0) = \lim_{h \to 0} \frac{f(x_0 + hu_1, y_0 + hu_2) - f(x_0, y_0)}{h}\]
provided this limit exists.
Computing this limit directly is tedious. Instead, we can use the partial derivatives with respect to \(x\) and \(y\). This brings us to the central engine of multivariable calculus, which packages these partial derivatives into a single vector object called the gradient.
If \(f(x, y)\) has continuous first-order partial derivatives, the gradient of \(f\), denoted \(\nabla f\), is the vector-valued function defined by
\[\nabla f(x, y) = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right)\]
If \(f\) is differentiable at \((x_0, y_0)\) and \(u\) is a unit vector, then the directional derivative can be computed as a dot product:
\[D_u f(x_0, y_0) = \nabla f(x_0, y_0) \cdot u\]
Geometrically, the dot product tells us something wonderful. Since \(a \cdot b = |a||b|\cos(\theta)\), the directional derivative is maximised when the angle \(\theta\) between the gradient vector and our walking direction \(u\) is zero. In other words, the gradient vector points in the exact direction of the steepest ascent, and its magnitude \(|\nabla f|\) tells you just how steep that slope is. Conversely, walking opposite to the gradient gives the steepest descent.
Gradients and level sets
Picture a topographic map of a mountain. The contour lines connect points of equal elevation. These are level curves of the function \(f(x, y) = c\). If you walk along a contour line, your altitude does not change, meaning the directional derivative in the direction of the contour is zero. Since the directional derivative is a dot product with the gradient, and the dot product is zero when two vectors are perpendicular, the gradient vector must be perpendicular to the contour line at every point.
This geometric truth extends naturally to three dimensions, where a function \(f(x, y, z)\) has level surfaces given by \(f(x, y, z) = c\). At any point on this surface, the gradient vector \(\nabla f\) is orthogonal to the tangent plane of the level surface. This orthogonality gives us a direct way to find tangent planes.
Example 5.1: Tangent plane to an ellipsoid
Find the tangent plane to the ellipsoid \(x^2 + 2y^2 + 3z^2 = 6\) at \((1, 1, 1)\).
Solution.
Let \(f(x, y, z) = x^2 + 2y^2 + 3z^2\). The ellipsoid is the level surface \(f(x, y, z) = 6\).
Compute the partial derivatives of \(f\):
\(\frac{\partial f}{\partial x} = 2x\), \(\frac{\partial f}{\partial y} = 4y\), \(\frac{\partial f}{\partial z} = 6z\).
Evaluate the gradient vector \(\nabla f = (2x, 4y, 6z)\) at the point \((1, 1, 1)\):
\(\nabla f(1, 1, 1) = (2(1), 4(1), 6(1)) = (2, 4, 6)\).
This vector is normal to the tangent plane at the given point.
The equation of the tangent plane with normal vector \((A, B, C) = (2, 4, 6)\) passing through \((x_0, y_0, z_0) = (1, 1, 1)\) is \(A(x - x_0) + B(y - y_0) + C(z - z_0) = 0\).
Substitute the values: \(2(x - 1) + 4(y - 1) + 6(z - 1) = 0\).
Expand the expression: \(2x - 2 + 4y - 4 + 6z - 6 = 0\).
Simplify the equation: \(2x + 4y + 6z = 12\).
Divide the entire equation by \(2\) to obtain the final answer:
\(x + 2y + 3z = 6\).
Critical points
In single variable calculus, you find peaks and valleys by setting the derivative to zero and checking the second derivative. In two variables, a critical point is a location where the tangent plane is completely horizontal, meaning the surface is flat in all directions.
A point \((x_0, y_0)\) is a critical point of \(f(x, y)\) if both first-order partial derivatives are zero simultaneously:
\[\frac{\partial f}{\partial x}(x_0, y_0) = 0 \quad \text{and} \quad \frac{\partial f}{\partial y}(x_0, y_0) = 0\]
Alternatively, the gradient is the zero vector: \(\nabla f(x_0, y_0) = (0, 0)\).
Just like in single variable calculus, having a zero derivative does not guarantee a local maximum or minimum. You could be sitting on a saddle point, which curves up in one direction and down in another, much like a horse riding saddle. To classify these points, we use the second derivative test.
Suppose that the second partial derivatives of \(f\) are continuous on a disk centered at a critical point \((x_0, y_0)\), and let the discriminant \(D\) be defined as
\[D = f_{xx}(x_0, y_0) f_{yy}(x_0, y_0) - [f_{xy}(x_0, y_0)]^2\]
- If \(D > 0\) and \(f_{xx}(x_0, y_0) > 0\), then \((x_0, y_0)\) is a local minimum.
- If \(D > 0\) and \(f_{xx}(x_0, y_0) < 0\), then \((x_0, y_0)\) is a local maximum.
- If \(D < 0\), then \((x_0, y_0)\) is a saddle point.
- If \(D = 0\), the test is inconclusive.
Example 5.2: Critical point classification
Find and classify the critical point of \(f = x^2 + 2y^2 - 4x + 4y\).
Solution.
Compute the first-order partial derivatives:
\(\frac{\partial f}{\partial x} = 2x - 4\)
\(\frac{\partial f}{\partial y} = 4y + 4\)
Set both derivatives to zero to find the critical point:
\(2x - 4 = 0 \implies x = 2\)
\(4y + 4 = 0 \implies y = -1\)
The only critical point is \((2, -1)\).
Compute the second-order partial derivatives:
\(f_{xx} = \frac{\partial}{\partial x}(2x - 4) = 2\)
\(f_{yy} = \frac{\partial}{\partial y}(4y + 4) = 4\)
\(f_{xy} = \frac{\partial}{\partial x}(4y + 4) = 0\)
Calculate the discriminant \(D\) at the critical point:
\(D = f_{xx}f_{yy} - f_{xy}^2 = (2)(4) - (0)^2 = 8\).
Since \(D > 0\) and \(f_{xx} = 2 > 0\), the point is a local minimum.
Evaluate the function at the critical point to find its value:
\(f(2, -1) = (2)^2 + 2(-1)^2 - 4(2) + 4(-1) = 4 + 2 - 8 - 4 = -6\).
Conclusion: a local minimum at \((2, -1)\) with value \(-6\).
Absolute extrema
Finding local bumps and dips is useful, but in real-world applications, we often need to find the absolute highest and lowest values of a function over a restricted domain. Think of finding the global maximum profit or minimum stress over a specified mechanical part.
If \(f(x, y)\) is continuous on a closed, bounded region \(R\) in the plane, then \(f\) attains an absolute maximum value and an absolute minimum value at least once in \(R\).
To find these absolute extrema, we follow a strict procedure. A closed and bounded region includes its interior and its boundary curve. Therefore, the absolute extreme values must occur either at interior critical points where the gradient is zero, or along the boundary of the region.
- Find all critical points of \(f\) that lie strictly inside the region \(R\), and calculate their function values.
- Find the maximum and minimum values of \(f\) along the entire boundary curve of \(R\).
- Compare all the values found in the previous steps. The largest is the absolute maximum, and the smallest is the absolute minimum.
Lagrange multipliers
Often, optimisation problems come with rules or restrictions. You might want to maximise the volume of a box, but your manufacturing budget restricts the total surface area you can use. This means we are no longer searching the entire xy-plane; we are restricted to walking along a specific constraint curve defined by an equation \(g(x, y) = k\).
Geometrically, as you walk along the constraint curve \(g(x, y) = k\), you cross various level curves of your objective function \(f(x, y)\). The maximum or minimum values along this constraint curve occur precisely where a level curve of \(f\) is tangent to the constraint curve. Since the gradient of any function is always perpendicular to its level curves, two curves are tangent when their gradient vectors point in the same or opposite directions. This means \(\nabla f\) must be a scalar multiple of \(\nabla g\).
To find the maximum and minimum values of \(f(x, y)\) subject to the constraint \(g(x, y) = k\), assuming that \(\nabla g \neq 0\) on the constraint curve, solve the system of equations:
\[\nabla f(x, y) = \lambda \nabla g(x, y)\]
\[g(x, y) = k\]
Here, the scalar \(\lambda\) is called the Lagrange multiplier.
Example 5.3: Constrained optimisation
Maximise \(xy\) subject to \(2x + y = 8\).
Solution.
Let the objective function be \(f(x, y) = xy\), and let the constraint function be \(g(x, y) = 2x + y = 8\).
Compute the gradients:
\(\nabla f = (y, x)\)
\(\nabla g = (2, 1)\)
Set up the Lagrange multiplier equations \(\nabla f = \lambda \nabla g\):
\(y = 2\lambda\)
\(x = \lambda\)
Include the constraint equation:
\(2x + y = 8\)
Substitute \(\lambda\) from the second equation into the first equation: since \(\lambda = x\), we have \(y = 2x\).
Substitute \(y = 2x\) into the constraint equation:
\(2x + (2x) = 8\)
Simplify and solve for \(x\):
\(4x = 8 \implies x = 2\).
Find the corresponding value for \(y\):
\(y = 2(2) = 4\).
Thus, the only candidate point is \((2, 4)\).
Evaluate the objective function at this point to check the value:
\(f(2, 4) = (2)(4) = 8\).
Since the problem asks to maximise \(xy\) on a line segment that stretches infinitely, checking boundary points is not needed here, and testing another nearby point on the constraint like \((3, 2)\) gives \(f(3, 2) = 6\), confirming our value is indeed a maximum.
Conclusion: maximum \(8\) at \((2, 4)\).
Practice
Practice 1: try it first
Find the directional derivative of \(f = x^2 - y^2\) at \((3, 1)\) towards \((6, 5)\).
Show the answer
\(10/5 = 2\)
Practice 2: try it first
Classify the critical point of \(f = x^2 - y^2 + 2x\).
Show the answer
a saddle point at \((-1, 0)\)
Practice 3: try it first
Find the minimum of \(x^2 + y^2 + z^2\) on the plane \(x + y + z = 3\).
Show the answer
\(3\) at \((1,1,1)\)
Want a hint instead of an answer? Practise this chapter with the tutor.