Multivariable calculus

Gradient of e^x cos(y): Components and Magnitude

For f(x, y) = e^x cos(y) the gradient is the vector (e^x cos y, -e^x sin y). Each partial treats the other variable as a constant, so the x partial reproduces the function and the y partial picks up the minus sign from the derivative of cosine. The length of this gradient is e^x at every point.

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

A product where each factor owns one variable

No chain rule and no product rule are needed here. The factor cos⁡y\cos y contains no xx, so for ∂f∂x\frac{\partial f}{\partial x} it is just a constant multiplier sitting in front of exe^{x}.

∂f∂x=cos⁡y⋅ddx(ex)=excos⁡y\frac{\partial f}{\partial x} = \cos y \cdot \frac{d}{dx}\left(e^{x}\right) = e^{x}\cos y

Swap roles for the other component. Now exe^{x} is the constant and cos⁡y\cos y is live, and the derivative of cosine carries a minus sign.

∂f∂y=ex⋅ddy(cos⁡y)=−exsin⁡y\frac{\partial f}{\partial y} = e^{x}\cdot \frac{d}{dy}\left(\cos y\right) = -e^{x}\sin y

The xx partial coming back as ff itself is not a coincidence to be suspicious of. Differentiating exe^{x} returns exe^{x}, and the yy factor never moved.

The length is e^x, and the direction spins with y

Factor exe^{x} out of the gradient and the Pythagorean identity finishes the magnitude.

∣∇f∣=excos⁡2y+sin⁡2y=ex\left|\nabla f\right| = e^{x}\sqrt{\cos^{2} y + \sin^{2} y} = e^{x}

So the steepness of this surface depends only on xx. Move along a vertical line and the surface rises and falls, yet the maximum rate of change never changes size; only the direction of steepest ascent rotates, tracing the unit vector ⟨cos⁡y,−sin⁡y⟩\left\langle \cos y, -\sin y\right\rangle as yy increases.

The gradient is never the zero vector, since ex>0e^{x} > 0 and cos⁡y\cos y and sin⁡y\sin y never vanish at the same yy. This surface has no critical points at all.

One more property worth carrying forward: the second partials cancel, fxx+fyy=excos⁡y−excos⁡y=0f_{xx} + f_{yy} = e^{x}\cos y - e^{x}\cos y = 0, so ff is harmonic. It is the real part of eze^{z} in complex variables, which is where this example usually reappears.

The mistake: losing the minus sign, or chain-ruling the exponential

Two errors dominate on this page.

  • Writing ∂f∂y=exsin⁡y\frac{\partial f}{\partial y} = e^{x}\sin y without the minus. Then the gradient points the wrong way in the yy direction, and the linear approximation predicts the surface rising where it actually falls.
  • Writing ∂f∂y=excos⁡y⋅(something)\frac{\partial f}{\partial y} = e^{x}\cos y \cdot (\text{something}), as if the exponential needed a chain rule in yy. Its exponent is xx alone, so with respect to yy it is a frozen constant.

Check at (0,0)(0, 0): ∇f(0,0)=⟨1,0⟩\nabla f(0,0) = \left\langle 1, 0 \right\rangle. The surface at that point is level in the yy direction, which matches cos⁡y\cos y having a maximum at y=0y = 0. A wrong sign would not show up here, so test at (0,π2)(0, \frac{\pi}{2}) as well, where ∇f=⟨0,−1⟩\nabla f = \left\langle 0, -1 \right\rangle and ff is clearly decreasing in yy.

Frequently asked questions

Why does the magnitude of the gradient not depend on yy?

Because the two components are excos⁡ye^{x}\cos y and −exsin⁡y-e^{x}\sin y, and squaring and adding them gives e2x(cos⁡2y+sin⁡2y)=e2xe^{2x}(\cos^{2}y + \sin^{2}y) = e^{2x}. The yy dependence sits entirely in the direction of the vector, not its length.

Does excos⁡ye^{x}\cos y have any maximum or minimum?

No. A local extremum needs ∇f=⟨0,0⟩\nabla f = \left\langle 0,0\right\rangle, and that would force cos⁡y=0\cos y = 0 and sin⁡y=0\sin y = 0 at the same yy, which is impossible. On any closed bounded region the extreme values are therefore on the boundary.