Multivariable calculus

Gradient of x^2 + xy + y^2: Handling the Cross Term

For f(x, y) = x^2 + xy + y^2 the gradient is (2x + y, x + 2y). The cross term xy contributes to both components: it leaves a y in the x-slot and an x in the y-slot. At (2, -1) the gradient is (3, 0), and the only critical point is the origin.

f(x,y)=x2+xy+y2f(x,y) = x^2 + xy + y^2
f(x,y)=2x+y, x+2y\nabla f(x,y) = \left\langle 2x + y,\ x + 2y \right\rangle
fx=2x+y\frac{\partial f}{\partial x} = 2x + y
fy=x+2y\frac{\partial f}{\partial y} = x + 2y

Differentiate all three terms, including the cross term

Go term by term with yy frozen. The square x2x^2 gives 2x2x. The cross term xyxy is yy times xx, so it gives yy. The square y2y^2 is a pure constant and gives zero.

fx=2x+y+0=2x+y\frac{\partial f}{\partial x} = 2x + y + 0 = 2x + y

Repeat with xx frozen. Now x2x^2 is the constant, xyxy is xx times yy and gives xx, and y2y^2 gives 2y2y.

fy=0+x+2y=x+2y\frac{\partial f}{\partial y} = 0 + x + 2y = x + 2y
f(x,y)=2x+y, x+2y\nabla f(x,y) = \left\langle 2x + y,\ x + 2y \right\rangle

At (2,1)(2,-1) this is 41, 22=3,0\langle 4 - 1,\ 2 - 2\rangle = \langle 3, 0\rangle, pointing due east. The height there is f(2,1)=42+1=3f(2,-1) = 4 - 2 + 1 = 3.

The mistake: charging the cross term to only one component

A frequent answer is 2x+y,2y\langle 2x + y, 2y\rangle, where xyxy has been used up in the xx-component and forgotten in the yy-component. Each partial derivative is computed from scratch on the whole function, so a term that contains both variables gets counted in both.

You can catch the error by slicing. Fix x=2x = 2, so g(y)=f(2,y)=4+2y+y2g(y) = f(2,y) = 4 + 2y + y^2 is a one-variable function with g(y)=2+2yg'(y) = 2 + 2y. The correct formula gives x+2y=2+2yx + 2y = 2 + 2y, which matches. The faulty formula gives 2y2y, which does not.

  • Ask of every term: does it contain the variable I am differentiating? If yes, it contributes.
  • xyxy contains both variables, so it contributes to both components.
  • Slice-and-check with a fixed numeric value for the other variable is the fastest way to verify a suspect component.

A quadratic form, so the gradient is a linear map

Every component is linear in xx and yy, which is what always happens for a quadratic form. You can write the gradient as a matrix acting on the position vector.

f(x,y)=[2112][xy]\nabla f(x,y) = \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

That matrix is invertible, so the only solution of f=0\nabla f = \mathbf{0} is x=y=0x = y = 0. Since f=(x+y2)2+34y2f = \left(x + \tfrac{y}{2}\right)^2 + \tfrac{3}{4}y^2 is a sum of squares, the origin is a global minimum with value 00.

The level curves x2+xy+y2=cx^2 + xy + y^2 = c are ellipses tilted at 4545 degrees, with the long axis along y=xy = -x. Setting y=xy = -x gives f=x2f = x^2, which grows slowly, while y=xy = x gives f=3x2f = 3x^2, which grows fast. The gradient is longest where the level curves crowd together, along y=xy = x.

Frequently asked questions

Is the origin a minimum for x^2 + xy + y^2?

Yes, a global minimum. The second derivative test gives fxx=2f_{xx} = 2, fyy=2f_{yy} = 2, fxy=1f_{xy} = 1 and D=41=3>0D = 4 - 1 = 3 > 0 with fxx>0f_{xx} > 0, which confirms a local minimum, and the sum-of-squares form makes it global.

Where is the gradient of x^2 + xy + y^2 horizontal?

Wherever the second component vanishes without the first, meaning x+2y=0x + 2y = 0 away from the origin. That is the line x=2yx = -2y with the origin removed, since at the origin the gradient is the zero vector and points nowhere at all. The point (2,1)(2,-1) sits on that line, and its gradient 3,0\langle 3, 0\rangle is indeed horizontal.