Multivariable calculus

Gradient of x cos(y) + y sin(x), Term by Term

For f(x, y) = x cos(y) + y sin(x) the gradient is (cos y + y cos x, sin x - x sin y). Differentiate one term at a time: in the x partial, cos y is a constant multiplier on x and y is a constant multiplier on sin x. The y partial follows the same rule with the roles reversed.

f(x,y)=xcosy+ysinxf(x,y) = x\cos y + y\sin x
f=cosy+ycosx,  sinxxsiny\nabla f = \left\langle \cos y + y\cos x,\; \sin x - x\sin y \right\rangle
fx=cosy+ycosx\frac{\partial f}{\partial x} = \cos y + y\cos x
fy=sinxxsiny\frac{\partial f}{\partial y} = \sin x - x\sin y

Two terms, four small derivatives

Split the function and handle each term on its own. For fx\frac{\partial f}{\partial x}, the term xcosyx\cos y has cosy\cos y as a frozen multiplier, and the term ysinxy\sin x has yy as a frozen multiplier.

x(xcosy)=cosy,x(ysinx)=ycosx\frac{\partial}{\partial x}\left(x\cos y\right) = \cos y, \qquad \frac{\partial}{\partial x}\left(y\sin x\right) = y\cos x
fx=cosy+ycosx\frac{\partial f}{\partial x} = \cos y + y\cos x

Now hold xx fixed. The term xcosyx\cos y has xx frozen and cosy\cos y live, which produces the minus sign, and the term ysinxy\sin x has sinx\sin x frozen.

y(xcosy)=xsiny,y(ysinx)=sinx\frac{\partial}{\partial y}\left(x\cos y\right) = -x\sin y, \qquad \frac{\partial}{\partial y}\left(y\sin x\right) = \sin x
fy=sinxxsiny\frac{\partial f}{\partial y} = \sin x - x\sin y

Every term of ff is a product of a bare variable and a trig function of the other variable, so no product rule is ever needed. Whichever variable you differentiate, one factor is a constant.

Checking the answer at a point

The origin is the cheapest test point, because sines vanish and cosines are 11.

f(0,0)=cos0+0cos0,  sin00sin0=1,  0\nabla f(0,0) = \left\langle \cos 0 + 0\cdot\cos 0,\; \sin 0 - 0\cdot\sin 0 \right\rangle = \left\langle 1,\; 0 \right\rangle

That is right: near the origin fxf \approx x, since xcosyxx\cos y \approx x and ysinxxyy\sin x \approx xy is second order. A function that behaves like xx has gradient 1,0\left\langle 1, 0\right\rangle.

Try a point where all four pieces are active, say (π2,π)\left(\frac{\pi}{2}, \pi\right).

f(π2,π)=cosπ+πcosπ2,  sinπ2π2sinπ=1,  1\nabla f\left(\tfrac{\pi}{2}, \pi\right) = \left\langle \cos\pi + \pi\cos\tfrac{\pi}{2},\; \sin\tfrac{\pi}{2} - \tfrac{\pi}{2}\sin\pi \right\rangle = \left\langle -1,\; 1 \right\rangle

Both components collapse neatly there because cosπ2\cos\frac{\pi}{2} and sinπ\sin\pi are zero. Points like that are worth hunting for when you want a quick sanity check with no decimals.

The mistake: leaking a term into the wrong component

The wrong answers here are almost always cross contamination: a piece that belongs to fy\frac{\partial f}{\partial y} appears in fx\frac{\partial f}{\partial x}. The classic is fx=xsiny+ycosx\frac{\partial f}{\partial x} = -x\sin y + y\cos x, where the first term was differentiated with respect to the wrong variable.

Unlike a symmetric function, this one gives you no shortcut check. Swapping xx and yy turns ff into ycosx+xsinyy\cos x + x\sin y, a different function, so the two components are genuinely not mirror images and you cannot verify one from the other.

  • In fx\frac{\partial f}{\partial x}, every trig function of yy must survive untouched. Seeing siny\sin y where the original had cosy\cos y means a yy derivative was taken by accident.
  • In fy\frac{\partial f}{\partial y}, every trig function of xx must survive untouched. Seeing cosx\cos x there is the same error mirrored.
  • The minus sign belongs to the yy component only, since only cosy\cos y gets differentiated anywhere.

Frequently asked questions

Why does fx\frac{\partial f}{\partial x} contain cosy\cos y but no siny\sin y?

Because cosy\cos y is a constant as far as xx is concerned. Differentiating with respect to xx can never turn a cosine of yy into a sine of yy, so any siny\sin y appearing in the xx component is a sign that a yy derivative was taken by mistake.

Do the mixed second partials agree for this function?

Yes, as Clairaut's theorem guarantees for a function this smooth. Differentiating cosy+ycosx\cos y + y\cos x with respect to yy gives siny+cosx-\sin y + \cos x, and differentiating sinxxsiny\sin x - x\sin y with respect to xx gives cosxsiny\cos x - \sin y. Same expression.