# How can I find the derivative of a function that takes in two variables?

We won't learn derivations in school for next 3 or 4 years, but I got interested in math and started learning about derivations on Khan Academy. I do understand what would a derivative of $f(x) = x^2$ be, but what if $f(x, y) = (x + y)(x + y)$ ? I guess i would need a three dimensional graph for that, and thus I wouldn't be looking for a tangent line, but more like a tangent surface of some sort? How can I express the "slope" of a surface? I guess that I need at least two numbers... I did some calculations, I'm pretty sure that they're wrong but I got that $f'(x, y) = 2x + 2y$, if given that $f(x, y) = (x + y)(x + y)$... This doesn't really make any sense to me, at all, so how do you do it?

-
this is a great question, and I am not sure you are ready for the answer yet. A great resource is en.wikipedia.org/wiki/Multivariable_calculus. It is taught in the 2nd year in college. – picakhu Nov 17 '11 at 15:27
Yes, nice intuition. Think of planes for your "tangent surface". – David Mitra Nov 17 '11 at 15:31
Thanks for that link! Although, I usually found it hard to learn from Wikipedia (but that can vary, depending on who wrote the article)... – jcora Nov 17 '11 at 15:36
@bane, you may like this more then. tutorial.math.lamar.edu/Classes/CalcIII/PartialDerivatives.aspx – picakhu Nov 17 '11 at 15:46

The usual thing one does (but this can vary according to what you're trying to achieve) is to compute a vector called the gradient of the function, notated $\nabla f$. The gradient has one component for each input to $f$; for each component you treat all other variables temporarily as constants and differentiate with respect to the chosen one: $$(\nabla f)(x,y) = \left(\frac{d}{dx}f(x,y), \frac{d}{dy}f(x,y)\right) = ( 2(x+y), 2(x+y) )$$ In this example it may be a bit hard to see what's going on, because both components end up being the same, so let's try another one: $g(x,y)=x^2y+y$ gives $$\nabla g(x,y) = (2xy, x^2+1)$$

The intuitive property of the gradient is that if we have some small offset $(h,k)$ from $(x,y)$, then the difference $f(x+h,y+k)-f(x,y)$ is closely approximated by the dot product between $(h,k)$ and $\nabla f(x,y)$.

The components of the gradient are called partial derivatives and are often notated with a special sign as $\frac{\partial f}{\partial x}$ and $\frac{\partial f}{\partial y}$. The $\partial$ sign looks a bit like a $d$, but is different as a reminder that a single partial derivative is not usually enough to estimate $\Delta f$; you need both of them.

-

A geometric way of thinking about the $n$-th derivative in one variable is that is the best possible $n$-th degree approximation to the function, after the lower derivatives have been subtracted away.

For example, the "0-th derivative" of $f(x)$ at $x_0$ is just the point $f(x_0)$.

Subtract $f(x_0)$ from $f$ and you get a function $f(x) - f(x_0)$ that crosses the $x$-axis at $x_0$. If you zoom in far enough at the point $x_0$, it looks like a line $y = a(x-x_0)$. This line is completely determined by its slope, which we call the first derivative.

Subtract off this line, and now your function $f(x) - f(x_0) - a(x-x_0)$ kisses the $x$-axis at $x_0$ without crossing it. Zoom in far enough and it looks like a quadratic, $\frac{1}{2}b(x-x_0)^2$. Again, the single number $b$ is enough to determine the shape of this quadratic, and we call this number the second derivative.

Now let's look at a two-dimensional function $f(x,y)$. Again, the degree 0 approximation at $(x_0,y_0)$ is just $f(x_0,y_0)$. Subtracting we get $f(x,y) - f(x_0,y_0)$, and if we zoom in this function looks like a plane that passes through the $x-y$ plane at $(x_0,y_0)$. This plane has equation $z = a(x-x_0) + b(y-y_0)$ for some coefficients $a$ and $b$ -- notice that now we need two numbers to completely specify this plane. This pair of numbers is the first derivative of $f$.

Subtracting again we will get a function that is tangent to the $x-y$ plane at $(x_0,y_0)$; zooming in, the surface looks like a degree 2 quadratic surface $z = \frac{1}{2} b(x-x_0)^2 + c(x-x_0)(y-y_0) + \frac{1}{2}(y-y_0)^2.$ The three numbers $b,c,d$ that determine this quadratic are the second derivative, often written as a matrix $\left[\begin{array}{cc} b & c\\ c & d\end{array}\right]$. This surface looks like either a bowl, an extruded parabola, or a saddle.

We can continue this process, approximating what's left of the function with cubic, quartic, etc. surface. But these require more and more numbers to determine, and are harder to visualize geometrically.

-