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)=excosyf(x,y) = e^{x}\cos y
f=excosy,  exsiny\nabla f = \left\langle e^{x}\cos y,\; -e^{x}\sin y \right\rangle
fx=excosy\frac{\partial f}{\partial x} = e^{x}\cos y
fy=exsiny\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 cosy\cos y contains no xx, so for fx\frac{\partial f}{\partial x} it is just a constant multiplier sitting in front of exe^{x}.

fx=cosyddx(ex)=excosy\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 cosy\cos y is live, and the derivative of cosine carries a minus sign.

fy=exddy(cosy)=exsiny\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=excos2y+sin2y=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 cosy,siny\left\langle \cos y, -\sin y\right\rangle as yy increases.

The gradient is never the zero vector, since ex>0e^{x} > 0 and cosy\cos y and siny\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=excosyexcosy=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 fy=exsiny\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 fy=excosy(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 cosy\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 excosye^{x}\cos y and exsiny-e^{x}\sin y, and squaring and adding them gives e2x(cos2y+sin2y)=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 excosye^{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 cosy=0\cos y = 0 and siny=0\sin y = 0 at the same yy, which is impossible. On any closed bounded region the extreme values are therefore on the boundary.