Gradient vector for a function of two variables For the function $z = x^2 + y^2 , z = f(x,y)$
the gradient comes out to be $(2x,2y)$.
However since the function is in 3D , shouldn't the gradient also be a 3D vector?
How would the gradient change if $w = f(x,y,z) = x^2 + y^2 -z =0$?
Will it be $(2x,2y, -1)$?
 A: Maybe you confuse $f$ with its graph. The graph of $f$ is three dimensional, i.e., a subset of $\mathbb{R}^3$. But $f$ has only two entries. For every partial differentiable function $f = f(x, y)$ the gradient of $f$ is defined as $(\partial_x f, \partial_y f)$, so the gradient is a planar vector in this case.
If you consider $w(x, y, z) = x^2 + y^2 - z$, then $w$ depends on three variables and therefore the gradient is a three dimensional vector $(\partial_x w, \partial_y w, \partial_z w) = (2x, 2y, -1)$. 
In the most general case, if $g = g(x_1, \dots, x_n)$ is a function of $n$ real variables, then $g$ has a graph 
$$\Gamma = \{ (x_1, \dots, x_n, y) : y = g(x_1, \dots, x_n) \} \subseteq \mathbb{R}^{n + 1}$$
and a gradient 
$$\nabla g = (\partial_{x_1} g, \dots, \partial_{x_n} g) \in \mathbb{R}^n.$$
A: If you define $f:\mathbb R^2\to\mathbb R$ as $f(x,y) = x^2 + y^2$, that's a two-dimensional function and its gradient is $\nabla f(x,y) = (2x, 2y)$.
When you write $z=f(x,y)$, what you are defining is a set in $\mathbb R^3$ which is known as the graph of $f$. Specifically, $\Gamma(f)=\{(x,y,z)\in\mathbb R^3:z=f(x,y)\}$. In this case, it's a paraboloid.
If you define another function $g:\mathbb R^3\to\mathbb R$ as $g(x,y,z) = f(x,y) - z = x^2+y^2-z$, then its gradient is $\nabla g(x,y,z) = (2x, 2y, -1)$. Now, the zero level curve for $g$, $\{(x,y,z)\in\mathbb R^3:g(x,y,z)=0\}$, coincides with $\Gamma(f)$ and $\nabla g$ is orthogonal to it.
