15.8 Lagrange Multipliers

Example

Find the extreme values of f(x, y)= 2  (x^3) +  (y^4), subject to the constraint (x^2) + (y^2) =  1.

grad[h_]  :=  {D[h, x],  D[h, y]}

f  =  2  (x^3)  +  (y^4);  g  =  (x^2) + (y^2);

grad[f]  ==  lambda grad[g]

Solve[{grad[f]  ==  lambda grad[g],  g  ==  1}]

The real solutions are (x, y)  =  (±1, 0), (0, ±1), (1/2,  ±(Sqrt[3])/2).

f  /.  {{x -> -1, y -> 0}, {x -> (1/2), 
          y -> -((Sqrt[3])/2)}, {x -> (1/2), 
          y -> ((Sqrt[3])/2)}, {x -> 0, y -> -1}, {x -> 0, 
          y -> 1}, {x -> 1, y -> 0}}

The maximum value is 2 at (1, 0);  the minimum value is -2  at (-1, 0).

x  =  r Cos[t];  y  =  r Sin[t];

p = 
        ParametricPlot3D[ {x, y, f},  {r, 0, 1}, {t, 0, 2  π}, 
          PlotPoints -> 30];

c  =  
        ParametricPlot3D[{x, y, 0} /. r -> 1, {t, 0, 
            2  π}];

b  =  
        ParametricPlot3D[{x, y, f} /. r -> 1, {t, 0, 
            2  π}];

Show[c, p, ViewPoint -> {-2.473,  -1.869,  1.356}, 
      PlotRange -> {-2, 2}]

Show[b, c, ViewPoint -> {-2.473,  -1.869,  1.356}, 
      PlotRange -> {-2, 2}]

Example

Find the extreme values of f(x, y)= 3  (x^2) - x y +  (y^2), subject to the constraint  3  (x^2) + (y^2) =  3.

Clear[x, y]
f  =  3  (x^2) -  x y  +  (y^2);  
    g  =  3 (x^2)  +  (y^2);

grad[f]  ==  lambda grad[g]

lps  =  
      Solve[{grad[f]  ==  lambda grad[g],  g  ==  3}]

f  /.  lps

The maximum value of f is 3 + (Sqrt[3])/2 at the points ±(1/(Sqrt[2]), -(Sqrt[3/2])); the minimum value is 3 - (Sqrt[3])/2 at the points ±(1/(Sqrt[2]), (Sqrt[3/2])).

x  =  r Cos[t];  y  =  (Sqrt[3]) r Sin[t];

p = 
        ParametricPlot3D[ {x, y, f},  {r, 0, 1}, {t, 0, 2  π}, 
          PlotPoints -> 30];

c  =  
        ParametricPlot3D[{x, y, 0} /. r -> 1, {t, 0, 
            2  π}];

b  =  
        ParametricPlot3D[{x, y, 3  (x^2) - x y +  (y^2)} /. r -> 1, {t, 
            0, 2  π}];

Show[c, p, ViewPoint -> {-2.473,  -1.869,  1.356}]

Show[b, c, ViewPoint -> {-2.473,  -1.869,  1.356}]

Example

Find the extreme values of f(x, y, z)  =  (x^4) + (y^4) + (z^4) on the unit sphere (x^2) + (y^2) + (z^2) = 1.

Clear[x, y, z];
grad[h_]  :=  {D[h, x], D[h, y], 
          D[h, z]};
f  =  (x^4) + (y^4) + (z^4);  g  =  (x^2) + (y^2) + (z^2);

grad[f]  ==  lambda grad[g]

lps  =  
      Solve[{grad[f]  ==  lambda grad[g],  g  ==  1}]

f /. lps

The maximum value of f is 1 at the points (±1, 0, 0), (0, ±1, 0), (0, 0, ±1);  the minimum value is (1/3) at the points \(TraditionalForm\`\(1\/\@3\) \((\(±1\), \(±1\), \(±1\))\)\).

We can't graph a function of three variables, but there are ways to visualize the different values of f on the sphere. One way is to create a sort of contour map by coloring or shading the points on the sphere according to the values of f at the points. The fourth coordinate c  in ParametricPlot3D[{x,y,z,c},...] can be used to specify a graphics function to shade or color the surface in this way. We'll use spherical coordinates (with ρ = 1) to parameterize the unit sphere.

x  =  Cos[t] Sin[p];  y  =  Sin[t] Sin[p];  
    z  =  Cos[p];
f  =  (x^4) + (y^4) + (z^4);

sphere  =  
        ParametricPlot3D[{x, y, z, Hue[f]}, {t, 0, 2  π}, {p, 0, π}, 
          Lighting -> False, PlotPoints -> 100];

ParametricPlot3D[] does not have an option to turn off the grid lines which obscure the colors. We can remove the grid lines ourselves with a little bit of Mathematica magic:

csphere  =  Prepend[sphere[[1]], EdgeForm[]];
colorsphere = 
      Show[Graphics3D[csphere], Lighting -> False]

Since red corresponds to higher values of f and green to lower values of f, we see that the maximum values of foccur where the coordinate axes intersect the sphere and the minimum values of f occur where the diagonals, \(TraditionalForm\`\(\(|\)\(x\)\(|\)\)\  = \ \(\(\(|\)\(y\)\(|\)\)\  = \ \(\(|\)\(z\)\(|\)\)\)\) intersect the sphere.

We can also shade the sphere with just two colors using RGBColor[f,0,1-f]. The higher values of f are shaded red and the lower values are shaded blue.

sphere  =  
        ParametricPlot3D[{x, y, z, RGBColor[f, 0, 1 - f]}, {t, 0, 
            2  π}, {p, 0, π}, Lighting -> False, 
          PlotPoints -> 100];

csphere =  Prepend[sphere[[1]], EdgeForm[]];
twocolorsphere = 
      Show[Graphics3D[csphere], Lighting -> False]

Let's plot the Lagrange points and combine them with the above color plots.

pts  =  {x, y, z} /. lps

lagrangepoints  =  
        Graphics3D[{PointSize[0.03], Map[Point, pts]}];

Show[colorsphere, lagrangepoints]

Show[twocolorsphere, lagrangepoints]

Example

Find the extreme values of f  =  x y  +  y z subject to the constraints x y  =  1 and (y^2) + (z^2) =   1.

Clear[x, y, z];
grad[h_]  :=  {D[h, x], D[h, y], 
          D[h, z]};
f  =  x y  +  y z;  g  =  x y;  
    h  =  (y^2) + (z^2);

grad[f]  ==  lambda grad[g]  +  mu grad[h]

lps  =  
      Solve[{grad[f]  ==  lambda grad[g]  +  mu grad[h], 
          g  ==  1,  h  ==  1}]

f  /.  lps

The maximum value of f is 3/2 at the points ±((Sqrt[2]), 1/(Sqrt[2]), 1/(Sqrt[2])); the minimum value is 1/2 at the points ±((Sqrt[2]), -1/(Sqrt[2]), 1/(Sqrt[2])).