# Visualizing the Lagrange Multiplier Solution

This question is based on work in Susan Colley's Vector Calculus, 4th ed.

The question is to find and classify critical points of $f(x,y,z)=3xy-4yz+5xz$ subject to the constraint $g(x,y,z)=3x+y+2z=13$. This gives us the critical point:

Clear[f, g, x, y, z];
f = 3 x y - 4 y z + 5 x z;
g = 3 x + y + 2 z;
Solve[{D[f, x] == \[Lambda] D[g, x], D[f, y] == \[Lambda] D[g, y],
D[f, z] == \[Lambda] D[g, z], g == 13}]

{{x -> 1196/409, y -> 715/409, z -> 507/409, \[Lambda] -> 1560/409}}


Manipulate[
Show[Plot3D[(13 - 3 x - y)/2, {x, -2, 5}, {y, -2, 5},
PlotStyle -> LightBlue, AxesLabel -> {x, y, z}, MeshStyle -> None],
ContourPlot3D[
3 x y - 4 y z + 5 x z == c, {x, -5, 5}, {y, -5, 5}, {z, -5, 10},
AxesLabel -> {x, y, z}, MeshStyle -> None,
PerformanceGoal -> "Quality"],
Graphics3D[{Black, Sphere[{1196/409, 715/409, 507/409}, 0.15]}],
BoxRatios -> {1, 1, .75}], {c, -15, 55, Appearance -> "Labeled"}]


Which produces:

The black sphere is the critical point located on the constraint plane. When I move the slider, I think of a circular neighborhood in the constraint plane surrounding the critical point. No matter how small the radius, the circle will contain function f values both larger and smaller than the function value at the critical point, which classifies the critical point as a saddle point.

She next states: "Finally, here is a plot of just the constraint plane and the critical point, but with the intersection of the level surfaces and the plane shown. " I made a small color change.

Show[Plot3D[(13 - 3 x - y)/2, {x, -2, 5}, {y, -2, 5},
PlotStyle -> LightBlue,
MeshFunctions -> {3*#1*#2 - 4 #2*#3 + 5*#1*#3 &}, Mesh -> 35,
AxesLabel -> {x, y, z}],
Graphics3D[{Black, Sphere[{1196/409, 715/409, 507/409}, 0.15]}],
BoxRatios -> {1, 1, .75}]


Amazing idea, which prompted me to see if I could label the mesh curves according to the wonderful suggestions made by @MichaelE2 on Adding z-value to mesh lines in Plot3D as is done in ContourPlot. So I tried:

Show[Plot3D[(13 - 3 x - y)/2, {x, -2, 5}, {y, -2, 5},
PlotStyle -> LightBlue,
MeshFunctions -> {3*#1*#2 - 4 #2*#3 + 5*#1*#3 &}, Mesh -> 35,
MeshStyle -> Thick,
AxesLabel -> {x, y, z}] /.
Line[pp_] :> Tooltip[Line[pp], plot[[1, 1, First[pp], 3]]],
Graphics3D[{Black, Sphere[{1196/409, 715/409, 507/409},
0.15]}], BoxRatios -> {1, 1, .75}]


Which produces:

However, when I begin hovering my mouse over the mesh curves, I don't get values that seem to agree with my first Manipulate image, so something is wrong? Either my interpretation or some sort of coding thing?

Using MichaelE2's SliceContourPlot3d:

Use Lagrange Multipliers to find the maximum and minimum values of the function $f(x,y,z)=xyz$ subject to the constraint $g(x,y,z)=x^2+2y^2+3z^2=6$.

Clear[f, g, x, y, z];
f = x y z;
g = x^2 + 2 y^2 + 3 z^2;
cpts = Solve[{Grad[f, {x, y, z}] == \[Lambda] Grad[g, {x, y, z}],
g == 6}, {x, y, z, \[Lambda]}, Reals];
Show[
SliceContourPlot3D[f, g == 6, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}],
Graphics3D[{
Red, PointSize[Large], Point[{x, y, z} /. cpts]
}]
]


Produces:

You all have taught me so much:

DynamicModule[{f, g, scp, cpts},
f = x y z;
g = x^2 + 2 y^2 + 3 z^2;
cpts = Solve[{Grad[f, {x, y, z}] == \[Lambda] Grad[g, {x, y, z}],
g == 6}, {x, y, z, \[Lambda]}, Reals];
scp = SliceContourPlot3D[f,
g == 6, {x, -3, 3}, {y, -3, 3}, {z, -3, 3}];
Manipulate[
Show[
scp,
ContourPlot3D[f == c, {x, -3, 3}, {y, -3, 3}, {z, -3, 3},
Mesh -> None, ContourStyle -> {Opacity[0.8], LightBlue},
PerformanceGoal -> "Quality"],
PlotLabel -> Pane[Row[{"f(x,y,z) = ", ToString[c]}], 100]
],
{{c, 0}, -1.2, 1.2, Appearance -> "Labeled"}]]


• @MichaelE2 I hope you get a chance to look at this question. Some amazing ideas here. Aug 10, 2015 at 18:30
• They've added a new function, SliceContourPlot3D[f, g == 13, {x, -5, 5}, {y, -5, 5}, {z, -5, 10}], that might be of use. Aug 10, 2015 at 19:27
• @MichaelE2 My goodness! Check out the update to my post where I have added an example using your idea. Aug 11, 2015 at 15:52
• It's enough to make Fabergé envious. :) Aug 11, 2015 at 16:20