Level Curves and Gradients

functions of 2 variables: their 3D plot and corresponding level curves

Example 1

Clear[f,x,y,xlo,ylo,xhi,yhi,numCon,p1,p2,p3,p0]
f[x_,y_]:=(y^2)-4 x y+4 (x^2)
xlo=ylo=-2.`;xhi=yhi=2.`;
numCon=25;
p0=Plot[0,{x,xlo,xhi},PlotRange->{{xlo,xhi},{ylo,yhi}},AxesLabel->{" x","y"},DisplayFunction->Identity];
p1=Plot3D[f[x,y],{x,xlo,xhi},{y,ylo,yhi},AxesLabel->{"x","y","z"},DisplayFunction->Identity];
p2=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},DisplayFunction->Identity];
p3=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},Contours->numCon,ContourShading->False,DisplayFunction->Identity];
Show[GraphicsGrid[{{p1},{p2,Show[p0,p3]}}]]

Clear[gradf, p4]
gradf[x_,y_] = {  D[ f[x,y],x], D[ f[x,y], y] }

p4=VectorPlot[gradf[x,y],{x,xlo,xhi},{y,ylo,yhi}];

Show[{p4,p3},Axes->True]

Example 2

Clear[f,x,y,xlo,ylo,xhi,yhi,numCon,p1,p2,p3,p0]
f[x_,y_]:=(y^2)-4 (x^2)
xlo=ylo=-3.`;xhi=yhi=3.`;
numCon=25;
p0=Plot[0,{x,xlo,xhi},PlotRange->{{xlo,xhi},{ylo,yhi}},AxesLabel->{" x","y"},DisplayFunction->Identity];
p1=Plot3D[f[x,y],{x,xlo,xhi},{y,ylo,yhi},AxesLabel->{"x","y","z"},DisplayFunction->Identity];
p2=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},DisplayFunction->Identity];
p3=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},Contours->numCon,ContourShading->False,DisplayFunction->Identity];
Show[GraphicsGrid[{{p1},{p2,Show[p0,p3]}}]]

Clear[gradf,p4]
gradf[x_,y_]={(∂_x)f[x,y],(∂_y)f[x,y]}
p4=VectorPlot[gradf[x,y],{x,xlo,xhi},{y,ylo,yhi}];Show[{p4,p3},Axes->True]

Example 3

Clear[f,x,y,xlo,ylo,xhi,yhi,numCon,p1,p2,p3]
f[x_,y_]:=((2 (x^2)+(y^2))/((x^2)+(y^2)));
xlo=ylo=-3.;xhi=yhi=3.;
numCon=10;
p1=Plot3D[f[x,y],{x,xlo,xhi},{y,ylo,yhi},AxesLabel->{"x","y","z"},DisplayFunction->Identity];
p2=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},DisplayFunction->Identity];
p3=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},Contours->numCon,ContourShading->False,DisplayFunction->Identity];
Show[GraphicsRow[{p1,p2,p3}]]

Clear[gradf,p4]
gradf[x_,y_]={(∂_x)f[x,y],(∂_y)f[x,y]}
p4=VectorFieldPlots`VectorFieldPlot[gradf[x,y],{x,xlo,xhi},{y,ylo,yhi}];
Show[{p4,p3},Axes->True]

Example 4

Clear[f,x,y,xlo,ylo,xhi,yhi,numCon,p1,p2,p3]
f[x_,y_]:=Sin[(Sqrt[(x^2)+(y^2)])];
xlo=ylo=-7.`;xhi=yhi=7.`;
numCon=10;
p1=Plot3D[f[x,y],{x,xlo,xhi},{y,ylo,yhi},AxesLabel->{"x","y","z"},DisplayFunction->Identity];
p2=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},DisplayFunction->Identity];
p3=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},Contours->numCon,ContourShading->False,DisplayFunction->Identity];
Show[GraphicsRow[{p1,p2,p3}]]

Clear[gradf,p4]
gradf[x_,y_]={(∂_x)f[x,y],(∂_y)f[x,y]}
p4=VectorPlot[gradf[x,y],{x,xlo,xhi},{y,ylo,yhi}];Show[{p4,p3},Axes->True]

Example 5

Clear[f,x,y,xlo,ylo,xhi,yhi,numCon,p1,p2,p3]
f[x_,y_]:=(x^4)-8 (y^2)-4 (x^2);
xlo=ylo=-3.`;xhi=yhi=3.`;
numCon=20;
p1=Plot3D[f[x,y],{x,xlo,xhi},{y,ylo,yhi},AxesLabel->{"x","y","z"},DisplayFunction->Identity];
p2=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},DisplayFunction->Identity];
p3=ContourPlot[f[x,y],{x,xlo,xhi},{y,ylo,yhi},Contours->numCon,ContourShading->False,DisplayFunction->Identity];
Show[GraphicsRow[{p1,p2,p3}]]

Clear[gradf,p4]
gradf[x_,y_]={(∂_x)f[x,y],(∂_y)f[x,y]}
p4=VectorPlot[gradf[x,y],{x,xlo,xhi},{y,ylo,yhi}];Show[{p4,p3},Axes->True]