# What's wrong in computing the gradient like this?

Say $u(x,y)=x^2+y^2$. Its gradient at (1,1) is (2,2).

Since I'm sure the gradient is directed towards y=x direction. I set y=x. Then $u(x,y)=2x^2=2y^2$. Now compute the gradient again. It's $\nabla u=(\partial_x u,\partial_y u)=(4x,4y)=(4,4)$. So what goes wrong here?

• $\partial_x$ depends on information about how $u$ behaves along the $x$-axis, so it can't be determined just from how $u$ behaves along the line $y = x$. – Qiaochu Yuan May 3 '12 at 3:34
• When you set $y = x$, you're not really looking at $u(x,y)$ anymore. Instead, you're really looking at some other function of one variable $g(x)$ which is defined by $g(x) = u(x,x) = x^2 + x^2 = 2x^2$. – Jesse Madnick May 3 '12 at 3:47

$$\partial_x u(x_0,y_0)=\lim_{h\to 0}\frac{u(x_0+h,y_0)-u(x_0,y_0)}{h},$$ and similarly for $\partial_y u$. If you restrict $u$ exclusively to the line $y=x$, then this difference quotient cannot be found. Even if $x_0=y_0$, notice that for all $h\neq 0$, $x_0+h\neq x_0$. Therefore the correct computation of the partial derivative $\partial_x u(x_0,x_0)$ is
\begin{align*} \partial_x u(x_0,x_0)&=\lim_{h\to 0}\frac{u(x_0+h,x_0)-u(x_0,x_0)}{h}\\ &=\lim_{h\to 0}\frac{(x_0+h)^2+x_0^2-2x_0^2}{h}\\ &=\lim_{h\to 0}\frac{2x_0h+h^2}{h}\\ &=2x_0, \end{align*}
and similarly for $\partial_yu(x_0,x_0)$.
You could consider the single variable function $f(x):=u(x,x)$, but that is another story. Its derivative tells you how $u$ changes along the line $y=x$. In fact, $f'(x)$ is $\sqrt 2$ times the directional derivative of $u$ in the direction of the unit vector $(1/\sqrt 2,1/\sqrt 2)$, which can also be computed as $\nabla u(x,x)\cdot (1,1) = 4x$.
• Thanks to all. You are all right. Jesse Madnick said $2x^2,2y^2,x^2+y^2$ are just three functions conciding on $y=x$ line. They don't necessarily share derivative information. And Jonas Meyer said if I intended to restrict the function on y=x, the gradient will no longer be meaningful. – Tim May 3 '12 at 4:05