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)=sinxcosyf(x,y) = \sin x \cos y
f=cosxcosy,  sinxsiny\nabla f = \left\langle \cos x \cos y,\; -\sin x \sin y \right\rangle
fx=cosxcosy\frac{\partial f}{\partial x} = \cos x \cos y
fy=sinxsiny\frac{\partial f}{\partial y} = -\sin x \sin y

Each factor is differentiated by its own variable

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

fx=cosyddx(sinx)=cosxcosy\frac{\partial f}{\partial x} = \cos y \cdot \frac{d}{dx}\left(\sin x\right) = \cos x \cos y
fy=sinxddy(cosy)=sinxsiny\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 cos2xcos2y+sin2xsin2y\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 cosx=0\cos x = 0 then x=π2+mπx = \frac{\pi}{2} + m\pi and sinx=±1\sin x = \pm 1, so the second equation needs siny=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 cosy=0\cos y = 0 then y=π2+nπy = \frac{\pi}{2} + n\pi and siny=±1\sin y = \pm 1, so the second equation needs sinx=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 sinxcosy\sin x \cos y looks like a product, students reach for the product rule and write fx=cosxcosysinxsiny\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 cosy\cos y has zero derivative with respect to xx.

x(sinxcosy)=cosxcosy+sinx0=cosxcosy\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 sinxsiny-\sin x \sin y is a product of two positive numbers with a minus in front. Concretely, for small positive yy the factor cosy\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 cosx=0\cos x = 0 and siny=0\sin y = 0 you get f=±1f = \pm 1, the extreme values of the whole surface, so those are maxima and minima. Where sinx=0\sin x = 0 and cosy=0\cos y = 0 you get f=0f = 0 with higher and lower ground on either side, which is a saddle.