Multivariable calculus

Divergence of F = (sin(xy), cos(xy))

For F(x, y) = (sin(xy), cos(xy)) the divergence is y cos(xy) minus x sin(xy). The chain rule on the first component brings down y; on the second it brings down x and a minus sign from the derivative of cosine. The two inner derivatives differ, and that is the step most often missed.

F(x,y)=sin(xy), cos(xy)\mathbf{F}(x,y) = \left\langle \sin(xy),\ \cos(xy) \right\rangle
Px=xsin(xy)=ycos(xy)\frac{\partial P}{\partial x} = \frac{\partial}{\partial x}\sin(xy) = y\cos(xy)
Qy=ycos(xy)=xsin(xy)\frac{\partial Q}{\partial y} = \frac{\partial}{\partial y}\cos(xy) = -x\sin(xy)
F=ycos(xy)xsin(xy)\nabla \cdot \mathbf{F} = y\cos(xy) - x\sin(xy)

Chain rule, with the inner derivative matched to the variable

Both components wrap the same inside function u=xyu = xy, but the inner derivative is not the same, because you are differentiating with respect to a different variable each time.

ux=y,uy=x\frac{\partial u}{\partial x} = y, \qquad \frac{\partial u}{\partial y} = x

First component, outer function sin\sin, differentiated with respect to xx.

xsin(xy)=cos(xy)ux=ycos(xy)\frac{\partial}{\partial x}\sin(xy) = \cos(xy)\cdot\frac{\partial u}{\partial x} = y\cos(xy)

Second component, outer function cos\cos, differentiated with respect to yy. The derivative of cos\cos carries the minus sign.

ycos(xy)=sin(xy)uy=xsin(xy)\frac{\partial}{\partial y}\cos(xy) = -\sin(xy)\cdot\frac{\partial u}{\partial y} = -x\sin(xy)

Add them and you are done. As a spot check, at (1,1)(1,1) the divergence is cos1sin10.3012\cos 1 - \sin 1 \approx -0.3012, so the field is a mild sink there.

The mistake: reusing the same inner factor twice

The wrong answer that shows up most often is ycos(xy)ysin(xy)y\cos(xy) - y\sin(xy). The inner derivative yy from the first term has been copied into the second, but the second term is differentiated with respect to yy, where the inner derivative of xyxy is xx.

A useful habit: before touching either component, write down both inner derivatives, ux=y\frac{\partial u}{\partial x} = y and uy=x\frac{\partial u}{\partial y} = x, and then reach for the one that matches the variable you are working in.

The other frequent wrong answer, ycos(xy)+xsin(xy)y\cos(xy) + x\sin(xy), drops the minus sign that comes from differentiating cosine. Both errors survive a glance at the shape of the answer, so the only defence is doing the two steps separately and in order.

Every arrow has length 1, and the divergence still grows

This field is worth a second look because its arrows never change size. The two components are sin(xy)\sin(xy) and cos(xy)\cos(xy), so the length of every arrow is sin2(xy)+cos2(xy)=1\sqrt{\sin^{2}(xy)+\cos^{2}(xy)} = 1. Only the direction varies from point to point.

Yet the divergence is not bounded. Collect the two terms with the standard combination of a sine and a cosine of the same angle and the size of the answer appears on its own.

ycos(xy)xsin(xy)=x2+y2cos(xy+φ),cosφ=yx2+y2,  sinφ=xx2+y2y\cos(xy) - x\sin(xy) = \sqrt{x^{2}+y^{2}}\,\cos\left(xy + \varphi\right), \qquad \cos\varphi = \frac{y}{\sqrt{x^{2}+y^{2}}},\ \ \sin\varphi = \frac{x}{\sqrt{x^{2}+y^{2}}}

So the divergence oscillates between r-r and rr, where rr is the distance from the origin. Walk out along any ray that is not one of the axes and the angle xyxy grows quadratically while the envelope rr grows only linearly, so the swings get both wider and faster. A field whose arrows all have length 11 can still be a strong source at one point and a strong sink a short step away.

  • On the whole xx axis, y=0y=0, both terms vanish and the divergence is exactly 00.
  • On the yy axis, x=0x=0, the divergence is just yy, which is the envelope rr at full size.
  • Everywhere else it sits somewhere between, at x2+y2cos(xy+φ)\sqrt{x^{2}+y^{2}}\cos(xy+\varphi).

The lesson generalises past this example: divergence reads how the direction of a field turns as you move, not how long its arrows are. Fixing the length of every arrow puts no ceiling whatsoever on the divergence.

Checked on every build: each component is differentiated numerically with respect to its own variable, and the sum is compared against the divergence above at six sample points.

Frequently asked questions

Why is the inner derivative y in one term and x in the other?

Because the inner function xyxy is differentiated with respect to a different variable each time. Holding yy fixed gives x(xy)=y\frac{\partial}{\partial x}(xy) = y; holding xx fixed gives y(xy)=x\frac{\partial}{\partial y}(xy) = x.

Where does the minus sign in the second term come from?

From the outer function. dducosu=sinu\frac{d}{du}\cos u = -\sin u, so the chain rule attaches a minus to the whole second term, giving xsin(xy)-x\sin(xy).