Lagrange Problems \302\251 2006 by Mike May, S.J.- maymk@slu.edu with an aside on solving systems of equations (Section 15.3) In prior semesters, students commented that they were having trouble with the homework from the section on Lagrange multipliers. This worksheet shows how to use Maple to check your work on those problems. First we look at the slick way that Maple gives an answer, but hides all the details. It uses the solve command to solve a system of equations. Then we step through the work needed to solve a system by hand.
<Text-field style="_cstyle259" layout="Heading 3"><Font bold="true">Finding constrained extrema of a function in two variables.</Font></Text-field> Problem #6) Find the extrema of f(x,y) = x*y subject to the constraint that g(x, y) = 4*x^2 +y^2 - 8 = 0. f := (x, y) -> x*y; g := (x, y) -> 4*x^2 + y^2 - 8; Zio2JEkieEc2IkkieUdGJUYlNiRJKW9wZXJhdG9yR0YlSSZhcnJvd0dGJUYlKiY5JCIiIjklRixGJUYlRiU= Zio2JEkieEc2IkkieUdGJUYlNiRJKW9wZXJhdG9yR0YlSSZhcnJvd0dGJUYlLCgqJDkkIiIjIiIlKiQ5JUYtIiIiISIpRjFGJUYlRiU= The method we have been studying 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); LCZJInlHNiIiIiIqJkknbGFtYmRhR0YkRiVJInhHRiRGJSEiKQ== LCZJInhHNiIiIiIqJkknbGFtYmRhR0YkRiVJInlHRiRGJSEiIw== 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}); NiY8JS9JJ2xhbWJkYUc2IiMiIiIiIiUvSSJ5R0YmIiIjL0kieEdGJkYoPCVGJC9GKyEiIy9GLiEiIjwlL0YlI0YzRilGKkYyPCVGNUYwRi0= This gives four solutions that we can plug in to find which is a maximum and which is a minimum. 'f(1,2)' = f(1,2); 'f(1,-2)' = f(1,-2); 'f(-1,2)' = f(-1,2); 'f(-1,-2)' = f(-1,-2); Ly1JImZHNiI2JCIiIiIiI0Yo Ly1JImZHNiI2JCIiIiEiI0Yo Ly1JImZHNiI2JCEiIiIiIyEiIw== Ly1JImZHNiI2JCEiIiEiIyIiIw== Thus we have maxima at (1,2) and (-1, -2) and minima at (1,-2) and(-1,2).
<Text-field style="_cstyle260" layout="Heading 3"><Font bold="true">Finding constrained extrema of a function in three variables.</Font></Text-field> This technique easily extends to problems in more variables and with more constraints. Problem # 11) Find the extrema of f(x, y, z) = 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; Zio2JUkieEc2IkkieUdGJUkiekdGJUYlNiRJKW9wZXJhdG9yR0YlSSZhcnJvd0dGJUYlLCg5JCIiIjklRi05JkYtRiVGJUYl Zio2JUkieEc2IkkieUdGJUkiekdGJUYlNiRJKW9wZXJhdG9yR0YlSSZhcnJvd0dGJUYlLCoqJDkkIiIjIiIiKiQ5JUYuRi8qJDkmRi5GLyEiIkYvRiVGJUYl Zio2JUkieEc2IkkieUdGJUkiekdGJUYlNiRJKW9wZXJhdG9yR0YlSSZhcnJvd0dGJUYlLCg5JCIiIjklISIiRi9GLUYlRiVGJQ== Note that since there are two constraints in this problem, we have two lambda variables in the system of equations, so that we have a system of five equations in five variables. 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); LCgiIiJGIyomJkknbGFtYmRhRzYiNiNGI0YjSSJ4R0YnRiMiIiMmRiY2I0YqRiM= LCgiIiJGIyomJkknbGFtYmRhRzYiNiNGI0YjSSJ5R0YnRiMiIiMmRiY2I0YqISIi LCYiIiJGIyomJkknbGFtYmRhRzYiNiNGI0YjSSJ6R0YnRiMiIiM= solve({g(x,y,z), h(x,y,z), L[x], L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LDYlUSJaRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0YnLUkjbW5HRiQ2JFEiMkYnL0Y7USdub3JtYWxGJy8lMXN1cGVyc2NyaXB0c2hpZnRHUSIwRidGQUYrRkE=) literally means the solutions of the equation -3 + 2z^2 = 0, or 2z^2 = 3. Therefore the solutions of the system of equations are (LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYrLUkjbWlHRiQ2I1EhRictRiM2Jy1JJm1mcmFjR0YkNigtRiM2JS1JI21uR0YkNiRRIjFGJy8lLG1hdGh2YXJpYW50R1Enbm9ybWFsRicvJStiYWNrZ3JvdW5kR1EuWzI1NSwyNTUsMjU1XUYnRjotRiM2JS1GNzYkUSIyRidGOkY9RjovJS5saW5ldGhpY2tuZXNzR1EiMUYnLyUrZGVub21hbGlnbkdRJ2NlbnRlckYnLyUpbnVtYWxpZ25HRkovJSliZXZlbGxlZEdRJmZhbHNlRictSSNtb0dGJDYtUSgmbWludXM7RidGOi8lJmZlbmNlR0ZPLyUqc2VwYXJhdG9yR0ZPLyUpc3RyZXRjaHlHRk8vJSpzeW1tZXRyaWNHRk8vJShsYXJnZW9wR0ZPLyUubW92YWJsZWxpbWl0c0dGTy8lJ2FjY2VudEdGTy8lJ2xzcGFjZUdRLDAuMjIyMjIyMmVtRicvJSdyc3BhY2VHRl5vLUYyNihGNC1GIzYlLUkmbXNxcnRHRiQ2Iy1GNzYkUSI2RidGOkY9RjpGRUZIRktGTUY9RjotRlE2LVEiLEYnRjpGVC9GV1EldHJ1ZUYnRlhGWkZmbkZobkZqbi9GXW9RJjAuMGVtRicvRmBvUSwwLjMzMzMzMzNlbUYnLUYjNigtRlE2LVEqJnVtaW51czA7RidGOkZURlZGWEZaRmZuRmhuRmpuRlxvRl9vRjFGUEZhb0Y9RjpGW3AtRiM2JkZmcEZhb0Y9RjpGK0Y9Rjo=) and (LUkl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90ZWN0ZWRHSShfc3lzbGliR0YlNiMiIichIiJGKSwmI0YzRipGKUYrRilGKywkKiRGMkYoRig= Ly1JImZHNiI2JSwmIyIiIiIiI0YpKiQtSSVzcXJ0RzYkJSpwcm90ZWN0ZWRHSShfc3lzbGliR0YlNiMiIichIiJGMywmI0YzRipGKUYrRjMsJEYrRjMsJCokRjJGKEY1
<Text-field style="_cstyle261" layout="Heading 3"><Font bold="true">Solving systems of equations by eliminating variables.</Font></Text-field> As stated above, this method gives answers but does not show how to solve the system of equations. We now look at the second example again, this time breaking 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 a variable and using the subs (for substitute) command to eliminate that variable. 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]; LyIiISwqKiRJInhHNiIiIiMiIiIqJEkieUdGJ0YoRikqJEkiekdGJ0YoRikhIiJGKQ== LyIiISwoSSJ4RzYiIiIiSSJ5R0YmISIiRilGJw== LyIiISwoIiIiRiUqJiZJJ2xhbWJkYUc2IjYjRiVGJUkieEdGKUYlIiIjJkYoNiNGLEYl LyIiISwoIiIiRiUqJiZJJ2xhbWJkYUc2IjYjRiVGJUkieUdGKUYlIiIjJkYoNiNGLCEiIg== LyIiISwmIiIiRiUqJiZJJ2xhbWJkYUc2IjYjRiVGJUkiekdGKUYlIiIj The first substitution we see comes from equation 2, where we see that x = y + 1. We make that substitution in all five equations. for i from 1 to 5 do eq[i] := subs(x = y+1, eq[i]); od; LyIiISwqKiQsJkkieUc2IiIiIkYpRikiIiNGKSokRidGKkYpKiRJInpHRihGKkYpISIiRik= LyIiIUYj LyIiISwoIiIiRiUqJiZJJ2xhbWJkYUc2IjYjRiVGJSwmSSJ5R0YpRiVGJUYlRiUiIiMmRig2I0YtRiU= LyIiISwoIiIiRiUqJiZJJ2xhbWJkYUc2IjYjRiVGJUkieUdGKUYlIiIjJkYoNiNGLCEiIg== LyIiISwmIiIiRiUqJiZJJ2xhbWJkYUc2IjYjRiVGJUkiekdGKUYlIiIj Notice that the substitution wipes out the equation that it came from. The next substitution comes from equation 5, with lambda[1] = -1/(2*z). for i from 1 to 5 do eq[i] := subs(lambda[1] = -1/(2*z), eq[i]); od; LyIiISwqKiQsJkkieUc2IiIiIkYpRikiIiNGKSokRidGKkYpKiRJInpHRihGKkYpISIiRik= LyIiIUYj LyIiISwoIiIiRiUqJkkiekc2IiEiIiwmSSJ5R0YoRiVGJUYlRiVGKSZJJ2xhbWJkYUdGKDYjIiIjRiU= LyIiISwoIiIiRiUqJkkiekc2IiEiIkkieUdGKEYlRikmSSdsYW1iZGFHRig2IyIiI0Yp LyIiIUYj Now we use equation 4 to eliminate lambda[2]. for i from 1 to 5 do eq[i] := subs(lambda[2] = 1 - y/z, eq[i]); od; LyIiISwqKiQsJkkieUc2IiIiIkYpRikiIiNGKSokRidGKkYpKiRJInpHRihGKkYpISIiRik= LyIiIUYj LyIiISwoIiIjIiIiKiZJInpHNiIhIiIsJkkieUdGKUYmRiZGJkYmRioqJkYoRipGLEYmRio= LyIiIUYj LyIiIUYj Solving equation 3 for z gives z = (2*y + 1)/2. solve(eq[3],z); LCZJInlHNiIiIiIjRiUiIiNGJQ== Substitute z = (2*y + 1)/2 into each equation for i from 1 to 5 do eq[i] := simplify(subs(z = (2*y+1)/2, eq[i])); od; LyIiISwoKiRJInlHNiIiIiMiIiRGJkYpIyIiIiIiJUYr LyIiIUYj LyIiIUYj LyIiIUYj LyIiIUYj We are now ready to solve for y. ansy := [solve(eq[1],y)]; NyQsJiMhIiIiIiMiIiIqJCIiJyNGJ0YmI0YlRiksJkYkRidGKCNGJ0Yp LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2I1EhRic= LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2I1EhRic= Recall that x = y +1 and z = y + 1/2. That gives us the same points as we obtained 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 as 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