Lagrange Multipliers with an aside on solving systems of equations Worksheet by Mike May, S.J. - maymk@slu.edu Revised by Russell Blyth - blythrd@slu.edu restart; In prior semesters, students commented that they had trouble with Lagrange multiplier problems. This worksheet shows how to use Maple to check your work on those problems. First we see a slick method that gives an answer, but hides all the details. It uses the solve command to solve the system of equations. Then we step through the work needed to solve the system by hand.
<Text-field style="Heading 2" layout="Heading 2">Finding constrained extrema of a function of two variables</Text-field> Example: Find the extrema of f(x,y) = x*y subject to the constraint g(x, y) = 4*x^2 +y^2 - 8 = 0. f := (x, y) -> x*y; g := (x, y) -> 4*x^2 + y^2 - 8; The method of Lagrange multipliers produces equations relating the partial derivatives of f and g with respect to x and with respect to y. L[x] := diff(f(x,y),x) - lambda*diff(g(x,y),x); L[y] := diff(f(x,y),y) - lambda*diff(g(x,y),y); We now solve the system of equations made up of the constraint and the relations on the partial derivatives. solve({g(x,y), L[x], L[y]}, {x, y, lambda}); This gives four solutions that we can substitute into the objective function to find the maximum and minimum values. 'f(1,2)' = f(1,2); 'f(1,-2)' = f(1,-2); 'f(-1,2)' = f(-1,2); 'f(-1,-2)' = f(-1,-2); Thus the maximum value, 2, occurs at (1,2) and (-1, -2) and the minimum values, -2, occurs at (1,-2) and (-1,2).
<Text-field style="Heading 2" layout="Heading 2">Finding constrained extrema of a function in three variables</Text-field> This technique easily extends to problems in more variables and with more constraints. Example: Find the extrema of f(x, y, y) = x + y + z subject to the constraints x^2 + y^2 + z^2 = 1 and x = y +1. f := (x, y, z) -> x + y + z; g := (x, y, z) -> x^2 + y^2 + z^2 - 1; h := (x, y, z) -> x - y - 1; L[x] := diff(f(x,y,z),x) + lambda[1]*diff(g(x,y,z),x) + lambda[2]*diff(h(x,y,z),x); L[y] := diff(f(x,y,z),y) + lambda[1]*diff(g(x,y,z),y) + lambda[2]*diff(h(x,y,z),y); L[z] := diff(f(x,y,z),z) + lambda[1]*diff(g(x,y,z),z) + lambda[2]*diff(h(x,y,z),z); solve({g(x,y,z), h(x,y,z), L[x], L[y], L[z]}, {x,y,z,lambda[1], lambda[2]}); Note that RootOf(-3 + 2_NiMqJCklIlpHIiIjIiIi) = \302\261NiMtJSVzcXJ0RzYjKiYiIiQiIiIiIiMhIiI=, so the solutions are at (x,y,z) = (NiUsJiomIiIiRiUiIiMhIiJGJSomRiVGJS0lJXNxcnRHNiMiIidGJ0YnLCZGJEYnRihGJywkRihGJw==) and (x,y,z) = (NiUsJiomIiIiRiUiIiMhIiJGJSomRiVGJS0lJXNxcnRHNiMiIidGJ0YlLCZGJEYnRihGJUYo). The first is the location of the minimum value, and the second the location of the maximum value: 'f(1/2-1/sqrt(6), -1/2-1/sqrt(6), -1/sqrt(6))' = f(1/2-1/sqrt(6), -1/2-1/sqrt(6), -1/sqrt(6)); 'f(1/2+1/sqrt(6), -1/2+1/sqrt(6), 1/sqrt(6))' = f(1/2+1/sqrt(6), -1/2+1/sqrt(6), 1/sqrt(6));
<Text-field style="Heading 2" layout="Heading 2">Solving systems of equations by eliminating variables</Text-field> As stated above, this method gives solutions but does not show how to solve the system of equations, which is often the most challenging part of solving a problem by the method of Lagrange multipliers. We now look at the second example again, and break down the problem of solving the system of equations into steps that could be reproduced by hand. We solve the system by repeatedly solving an equation for one variable and using the subs (for substitute) command to eliminate that variable from the other equations. Start by collecting the system of equations to be solved. eq[1] := 0 = g(x,y,z); eq[2] := 0 = h(x,y,z); eq[3] := 0 = L[x]; eq[4] := 0 = L[y]; eq[5] := 0 = L[z]; The first substitution we use comes from equation 2, where we see that x = y + 1. We make that substitution in all 5 equations. for i from 1 to 5 do eq1[i] := subs(x = y+1, eq[i]); od; Notice that the substitution wipes out the equation that it came from. The next substitution we choose comes from equation 5, with lambda[1] = -1/(2*z). for i from 1 to 5 do eq2[i] := subs(lambda[1] = -1/(2*z), eq1[i]); od; Now we use equation 4 to eliminate lambda[2], which is equal to 1 - y/z. for i from 1 to 5 do eq3[i] := subs(lambda[2] = 1 - y/z, eq2[i]); od; Solving equation 3 for z gives us z = y + 1/2. 'z'=solve(eq3[3],z); for i from 1 to 5 do eq4[i] := simplify(subs(z = y+1/2, eq3[i])); od; We are now ready to solve for y. ansy := [solve(eq4[1],y)]; Recall that x = y +1 and z = y + 1/2. That gives us the same solutions as above.
<Text-field style="Heading 2" layout="Heading 2">Exercises</Text-field> Use Maple to solve the following problems. On at least one of the problems solve the system of equations both ways shown above. Be sure to label your answers. Note that the last two problems require that you also check the interior of a region for extrema since they involve inequality constraints. 1) Find the extrema of f(x, y) = x^2 + y, subject to the constraint x^2 - y^2 = 1. 2) Find the extrema of f(x, y, z) = x + 3*y +5*z, subject to the constraint x^2 + y^2 + z^2 = 1. 3) Find the extrema of f(x, y) = xy, subject to the constraint x^2 + 2y^2 <= 1. 4) Find the extrema of f(x, y) = x^3 - y^2, subject to the constraint x^2 + y^2 <= 1