Extrema Examples and The Gradient 
(Gradient is NOT on the Final Exam)

Note that I do some work with Mathematica to put dots where we have extrema and saddle points. This is not stricly necessary, but is helpful in my opinion to see where things are occuring.

Example

Here is an equation for a surface, for which we want to determine the maximum. The surface in this case is defined over a restricted domain:

z=f(x,y)=((x+y)/(1+(x^2)+(y^4)-x))+(((x^2)-(y^2))/20), -3≤x≤3 and -3≤y≤3.

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

The maximum of the surface will occur where the tangent plane is horizontal (or on the boundary), which means we must solve

((∂z)/(∂x))=0
((∂z)/(∂y))=0

for (x,y).

eq1=D[f[x,y],x]==0
eq2=D[f[x,y],y]==0
Solve[{eq1,eq2},{x,y}]

We are getting a large amount of output, so we should switch to NSolve to get decimal approximations. On the final exam, you would be able to solve the system of equations by hand.

NSolve[{eq1,eq2},{x,y}]

We are only interested in the real valued solutions. There are five of them. Let’s create a contourplot and see if we can figure out which ones are max and which ones are mins.

p1 = {-1.3454404280108798`,1.3454404280108787`};
p2 = {2.6987738380369604`,0.6464592646050887`};
p3={-0.43007207369881334`,-1.9857637010817821`};
p4 ={0.8741220910565175`,0.5463630514076553`};
p5={-0.2761908152074454`,-0.7725509644088796`};

gp1=Graphics[{Red,Disk[p1,0.07]}];
gp2=Graphics[{Red,Disk[p2,0.07]}];
gp3=Graphics[{Red,Disk[p3,0.07]}];
gp4=Graphics[{Blue,Disk[p4,0.07]}];
gp5=Graphics[{Green,Disk[p5,0.07]}];

plot1=ContourPlot[f[x,y],{x,-3,3},{y,-3,3}];

Show[plot1,gp1,gp2,gp3,gp4,gp5]

Light color is higher value in Mathematica, so from the contour plot it looks like the maximum is at the blue dot (0.87,0.54) and the minimum is at the green dot (-0.27,-0.77). If you hover the mouse over the contour lines, Mathematica will tell you what the z value is on that line, so if you forget the lighter/higher bit, you could figure it out.

The red dots are neither max not mins, they are saddle points. At a saddle point, in one direction there is a min, but in the other direction we have a max. So the first derivatives are both zero, but we have no extrema. The extrema are surrounded by joined lines on the contour plot, but the saddle points are not.

Let's get a plot of the surface to check our answer. I am going to put little spheres where the extrema and saddle points are, to make them easier to identify.

D3p1 ={p1[[1]],p1[[2]],f[p1[[1]],p1[[2]]]};
D3p2 ={p2[[1]],p2[[2]],f[p2[[1]],p2[[2]]]};
D3p3 ={p3[[1]],p3[[2]],f[p3[[1]],p3[[2]]]};
D3p4 ={p4[[1]],p4[[2]],f[p4[[1]],p4[[2]]]};
D3p5 ={p5[[1]],p5[[2]],f[p5[[1]],p5[[2]]]};

D3gp1=Graphics3D[{Red,Sphere[D3p1,0.1]}];
D3gp2=Graphics3D[{Red,Sphere[D3p2,0.1]}];
D3gp3=Graphics3D[{Red,Sphere[D3p3,0.1]}];
D3gp4=Graphics3D[{Blue,Sphere[D3p4,0.1]}];
D3gp5=Graphics3D[{Green,Sphere[D3p5,0.1]}];

plot2=Plot3D[f[x,y],{x,-3,3},{y,-3,3}];

Show[plot2,D3gp1,D3gp2,D3gp3,D3gp4,D3gp5,PlotRange->All]

We've got it.

The Gradient (not on the final exam)

In Calculus III, you will also learn about an interesting object called the gradient. which is a vector that points in the direction of greatest increase at any point on the surface. Since partial derivatives are giving you the rates of change, it shouldn't be surprising that the gradient is given by
⟨((∂z)/(∂x)),((∂z)/(∂y))⟩
where the angles brackets are the typical notation for vector in mathematics. In Mathematica, this is given by

gradient={D[f[x,y],x],D[f[x,y],y]}

Here is a plot of the gradient for this surface. The length of the arrows represents the relative size of the slope of the tangent plane (longer arrows, greater slope). Notice the arrows are pointing towards the maximum

plot3=VectorPlot[gradient,{x,-3,3},{y,-3,3}];

Show[plot3,gp1,gp2,gp3,gp4,gp5,PlotRange->All]

If we overlay the gradient on the contour plot, we can see that the arrows are perpendicular to the contour lines (but to really see that we have to make sure the aspect ratio in the plot is set correctly!).

Show[plot1,plot3,gp1,gp2,gp3,gp4,gp5,AspectRatio->1]

Gradients are very important in geology and electromagnetism.

Geology: If z=f(x,y) represents the physical topology of the earth, the the negative of the gradient would represent the direction water would flow on the surface.

Electromagnetism: The gradient is used in Maxwell's equations to describe the relationship between electric and magentic fields.

Calculus III holds many other wonders, such as divergence, curl, Laplacian, Green's Thorem, Stokes theorem, and more! Calculus III also works out a formula for testing if a point you find is a max or a min, so you do not have to rely on contour plots to determine extrema. But that can wait until Calculus III.

The Gradient will not be on the final! But you may see it in other classes so I wanted you to see it here.

Problem 1

Here is an equation for a surface, for which we want to determine the maximum. The surface in this case is defined over a restricted domain:

z=f(x,y)=x+y+2, -2≤x≤2 and -3≤y≤3

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

The maximum of the surface will occur where the tangent plane is horizontal, which means we must solve

((∂z)/(∂x))=0
((∂z)/(∂y))=0

for (x,y).

eq1=D[f[x,y],x]==0
eq2=D[f[x,y],y]==0
Solve[{eq1,eq2},{x,y}]

What happened? Well, the surface z=f(x,y) is just a plane (linear in both x and y), so there are no points where the tangent plane is horizontal. This means the extrema occur on the boundary. A contour plot can show us this.

plot1=ContourPlot[f[x,y],{x,-2,2},{y,-3,3}]

Light color is higher value in Mathematica, so from the contour plot it looks like the maximum is at (2,3) and the minimum is at (-2,-3). If you hover the mouse over the contour lines, Mathematica will tell you what the z value is on that line, so if you forget the lighter/higher bit, you could figure it out.

f[-2,-3]
f[2,3]

Let's get a plot of the surface to check our answer.

plot2=Plot3D[f[x,y],{x,-2,2},{y,-3,3}]

We've got it.

Let’s also work out the gradient, just for kicks.

gradient={D[f[x,y],x],D[f[x,y],y]}

Here is a plot of the gradient for this surface. The length of the arrows represents the relative size of the slope of the tangent plane (longer arrows, greater slope).

plot3=VectorPlot[gradient,{x,-2,2},{y,-3,3}]

If we overlay the gradient on the contour plot, we can see that the arrows are perpendicular to the contour lines (but to really see that we have to make sure the aspect ratio in the plot is set correctly!).

Show[plot1,plot3,AspectRatio->6/4]

Problem 2

Find the extrema of the function f(x,y)=2(x^2)+3(y^2). Determine if the extrema represent a max or a min.

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

eq1=D[f[x,y],x]==0
eq2=D[f[x,y],y]==0
Solve[{eq1,eq2},{x,y}]

p1 = {0,0};
gp1=Graphics[{Green,Disk[p1,0.07]}];
plot1=ContourPlot[f[x,y],{x,-2,2},{y,-3,3}];

Show[plot1,gp1]

f[0,0]
f[2,3]

D3p1 ={p1[[1]],p1[[2]],f[p1[[1]],p1[[2]]]};

D3gp1=Graphics3D[{Green,Sphere[D3p1,0.2]}];

plot2=Plot3D[f[x,y],{x,-2,2},{y,-3,3}];

Show[plot2,D3gp1,PlotRange->All]

Notice my sphere is more like a flattish ellipse in this plot! So we have a minimmum of z=0 at (0,0). Here is the gradient, for your information.

gradient={D[f[x,y],x],D[f[x,y],y]}
plot3=VectorPlot[gradient,{x,-2,2},{y,-3,3}];

Show[plot1,plot3,gp1,AspectRatio->6/4]

Problem 3

Find the extrema of the function f(x,y)=exp(-(x^2)-(y^2)-(x^2)(y^2)-2x-y). Determine if the extrema represent a max or a min.

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

eq1=D[f[x,y],x]==0
eq2=D[f[x,y],y]==0
Solve[{eq1,eq2},{x,y}]

Looks nasty, so try NSolve instead.

NSolve[{eq1,eq2},{x,y}]

It looks like we only have one possible place for an extrema, at (-0.933355,-0.267215).

p1 = {-0.9333547768666507`,-0.26721518611995304`};
gp1=Graphics[{Blue,Disk[p1,0.07]}];
plot1=ContourPlot[f[x,y],{x,-3,3},{y,-3,3}];

Show[plot1,gp1]

From the contourplot, it looks like we have a max.

f[-0.933355,-0.267215]
f[0,3.]

D3p1 ={p1[[1]],p1[[2]],f[p1[[1]],p1[[2]]]};
D3gp1=Graphics3D[{Blue,Sphere[D3p1,0.1]}];
plot2=Plot3D[f[x,y],{x,-3,3},{y,-3,3},PlotRange->All];

Show[plot2,D3gp1,PlotRange->All]

So we have a max at the point. Again, here is the gradient for your information.

gradient={D[f[x,y],x],D[f[x,y],y]}
plot3=VectorPlot[gradient,{x,-3,3},{y,-3,3}];

Show[plot1,plot3,gp1]

Problem 4

Find the extrema of the function f(x,y)=9(x^2)-4(y^2). Determine if the extrema represent a max or a min.

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

eq1=D[f[x,y],x]==0
eq2=D[f[x,y],y]==0
Solve[{eq1,eq2},{x,y}]

p1 = {0,0};
gp1=Graphics[{Red,Disk[p1,0.07]}];
plot1=ContourPlot[f[x,y],{x,-3,3},{y,-3,3}];

Show[plot1,gp1]

f[0,0]
f[0,3]

D3p1 ={p1[[1]],p1[[2]],f[p1[[1]],p1[[2]]]};
D3gp1=Graphics3D[{Red,Sphere[D3p1,0.1]}];
plot2=Plot3D[f[x,y],{x,-3,3},{y,-3,3},PlotRange->All];

Show[plot2,D3gp1,PlotRange->All]

So we have a saddle point at (0,0). There are no extrema, unless we restrict the domain and the extrema would be on the boundary. Again, here is the gradient for your information.

gradient={D[f[x,y],x],D[f[x,y],y]}
plot3=VectorPlot[gradient,{x,-3,3},{y,-3,3}];

Show[plot1,plot3,gp1]