Gradients of scalar-valued functions

The function

Elliptic paraboloid

f[x_,y_] = x^2 +2 y^2

Hyperboloid

f[x_,y_]=x^2-2y^2

Top half of a torus

f[x_,y_]= Sqrt[1-(Sqrt[x^2+y^2]-2)^2]

The gradient

grad[x_,y_]=FullSimplify[{D[f[s,t],s],D[f[s,t],t]}]/.{s->x,t->y}

The point a=(a1,a2) of interest, and the linear approximation about the point

a1 =3;
a2 =-2;
a3 =f[a1,a2]
approx[x_,y_] = Simplify[a3 + grad[a1,a2].{x-a1,y-a2}]

Range of x and y values to plot

xmin = -4;
xmax = 4;
ymin = -4;
ymax = 4;

First graph the function and the linear approximation

point = Graphics3D[{PointSize->.05,Point[{a1,a2,a3}]}];
fgraph=Plot3D[f[x,y],{x,xmin,xmax},{y,ymin,ymax}];
approxgraph=Plot3D[approx[x,y],{x,xmin,xmax},{y,ymin,ymax}];
horizontal=Plot3D[a3,{x,xmin,xmax},{y,ymin,ymax}];
Show[fgraph,point]

Then graph the levet set, it’s tangent line at a, and the gradient vector field

point=Graphics[{PointSize->.05,Point[{a1,a2}]}];
levelset=ContourPlot[f[x,y]==a3,{x,xmin,xmax},{y,ymin,ymax}];
approxlevel=ContourPlot[approx[x,y]==a3 ,{x,xmin,xmax},{y,ymin,ymax}];
gradient = VectorPlot[grad[x,y],{x,xmin,xmax},{y,ymin,ymax}];
Show[levelset,point,AspectRatio->1]