Multivariable calculus

Gradient of sin(x)cos(y): The Egg Carton Surface

For f(x, y) = sin(x) cos(y) the gradient is (cos x cos y, -sin x sin y). Each partial differentiates only its own factor and leaves the other alone. The gradient is zero on a grid of points: the peaks and pits sit where x is an odd multiple of pi over 2 and y is a multiple of pi.

f(x,y)=sin⁡xcos⁡yf(x,y) = \sin x \cos y
∇f=⟨cos⁡xcos⁡y,  −sin⁡xsin⁡y⟩\nabla f = \left\langle \cos x \cos y,\; -\sin x \sin y \right\rangle
∂f∂x=cos⁡xcos⁡y\frac{\partial f}{\partial x} = \cos x \cos y
∂f∂y=−sin⁡xsin⁡y\frac{\partial f}{\partial y} = -\sin x \sin y

Each factor is differentiated by its own variable

The variables are already separated: sin⁡x\sin x holds all the xx dependence and cos⁡y\cos y holds all the yy dependence. So each partial derivative touches one factor and copies the other.

∂f∂x=cos⁡y⋅ddx(sin⁡x)=cos⁡xcos⁡y\frac{\partial f}{\partial x} = \cos y \cdot \frac{d}{dx}\left(\sin x\right) = \cos x \cos y
∂f∂y=sin⁡x⋅ddy(cos⁡y)=−sin⁡xsin⁡y\frac{\partial f}{\partial y} = \sin x \cdot \frac{d}{dy}\left(\cos y\right) = -\sin x \sin y

The minus appears in the second component only, because only there does a cosine get differentiated. Squaring and adding the two components gives cos⁡2xcos⁡2y+sin⁡2xsin⁡2y\cos^{2}x\cos^{2}y + \sin^{2}x\sin^{2}y, which never exceeds 11, so the steepest this surface ever gets is a slope of 11.

The grid of critical points

Setting both components to zero at once forces a case split, and each case gives a different kind of point.

  • If cos⁡x=0\cos x = 0 then x=π2+mπx = \frac{\pi}{2} + m\pi and sin⁡x=±1\sin x = \pm 1, so the second equation needs sin⁡y=0\sin y = 0, that is y=nπy = n\pi. At these points f=±1f = \pm 1: the peaks and the pits of the carton.
  • If instead cos⁡y=0\cos y = 0 then y=π2+nπy = \frac{\pi}{2} + n\pi and sin⁡y=±1\sin y = \pm 1, so the second equation needs sin⁡x=0\sin x = 0, that is x=mπx = m\pi. There f=0f = 0: the saddles between neighbouring bumps.

That interleaved grid of maxima, minima and saddles is why this surface is the standard picture of an egg carton, and why it shows up in every discussion of the second derivative test.

Away from the grid the gradient does real work. At (π4,π4)\left(\frac{\pi}{4}, \frac{\pi}{4}\right) both sine and cosine equal 22\frac{\sqrt{2}}{2}.

∇f(π4,π4)=⟨12,  −12⟩\nabla f\left(\tfrac{\pi}{4}, \tfrac{\pi}{4}\right) = \left\langle \tfrac{1}{2},\; -\tfrac{1}{2} \right\rangle

So from there the steepest climb runs diagonally, up in xx and back in yy.

The mistake: differentiating both factors at once

Because sin⁡xcos⁡y\sin x \cos y looks like a product, students reach for the product rule and write ∂f∂x=cos⁡xcos⁡y−sin⁡xsin⁡y\frac{\partial f}{\partial x} = \cos x \cos y - \sin x \sin y.

That expression is a real derivative, just not this one. By the angle addition formula it equals cos⁡(x+y)\cos(x+y), which is the xx partial of sin⁡(x+y)\sin(x+y). What it does to ff is add the two components of ∇f\nabla f together into one answer.

The product rule is not wrong so much as unnecessary. Apply it honestly and the extra term dies on its own, because cos⁡y\cos y has zero derivative with respect to xx.

∂∂x(sin⁡xcos⁡y)=cos⁡xcos⁡y+sin⁡x⋅0=cos⁡xcos⁡y\frac{\partial}{\partial x}\left(\sin x \cos y\right) = \cos x \cos y + \sin x \cdot 0 = \cos x \cos y

Test at (0,0)(0, 0) if you are unsure: the true gradient is ⟨1,0⟩\left\langle 1, 0 \right\rangle, while the mixed version also gives 11 for the first slot, so use (π4,π4)\left(\frac{\pi}{4}, \frac{\pi}{4}\right), where the truth is 12\frac{1}{2} and the mixed answer is 00.

Frequently asked questions

Why is the yy component negative when xx and yy are both small and positive?

Because −sin⁡xsin⁡y-\sin x \sin y is a product of two positive numbers with a minus in front. Concretely, for small positive yy the factor cos⁡y\cos y is decreasing, so increasing yy lowers the surface and the gradient must have a negative yy component.

How do you tell the peaks from the saddles without the second derivative test?

Read the value of ff. Where cos⁡x=0\cos x = 0 and sin⁡y=0\sin y = 0 you get f=±1f = \pm 1, the extreme values of the whole surface, so those are maxima and minima. Where sin⁡x=0\sin x = 0 and cos⁡y=0\cos y = 0 you get f=0f = 0 with higher and lower ground on either side, which is a saddle.