The Gradient Vector and Level Curves
Clear[f,x,y] f[x_,y_] = 5 - (x^2 + x y + y^2)
Here is a plot of some level curves f[x,y] = c.
a = -1;
b = 1;
levelcurves = ContourPlot[Evaluate[f[x,y]],{x,a,b},{y,a,b},
ContourSmoothing->Automatic,
AxesLabel->{"x","y"}];The lighter shading indicates larger values of f[x,y].
Here is the 3D plot of the surface z = f[x,y]:
surfaceplot =
ParametricPlot3D[{x,y,f[x,y]},{x,a,b},{y,a,b},
AxesLabel->{"x","y","f[x,y]"}];
The level curves are plots at the height f[x,y]=c.
Here is f[x,y] = 4.5:
c = 4.5;
Show[levelcurves,Contours->{c},ContourShading->False];Here is the plot of the intersection of the surface and the plane z = 4.5:
c = 4.5;
plane = ParametricPlot3D[{x,y,c},{x,a,b},{y,a,b},
PlotPoints->{2,2},DisplayFunction->Identity];
Show[surfaceplot,plane,DisplayFunction->$DisplayFunction];Consider f(x,y) = 2 x^2 + x y + y^2.
Clear[x,y,f] f[x_,y_] = 2 x^2 + x y + y^2; grad2[f][x,y]
Here is a part of the level curve f[x,y] = f[1.5,2].
levelcurve = ContourPlot[f[x,y],{x,0,3},{y,1,4},
Contours->{f[1.5,2]},ContourShading->False,
DisplayFunction->$DisplayFunction];These next two will plot the gradient vector.
Clear[x,y,t]
x0=1.5;
y0=2;
{x1,y1}=grad2[f][x,y]/.{x->1.5,y->2};
gradientp=vectorPlot[{{x0,y0}},{{x1,y1}}];This plots the level curve and the gradient at (1.5,2)
Show[levelcurve,gradientp,PlotRange->All,
AspectRatio->Automatic,AxesLabel->{"x","y"},
DisplayFunction->$DisplayFunction];Well...
Up to The Gradient