Lagrange Multipliers with Maple
Example 1. Let f(x,y)= x+y^2. Find the absolute and local extrema of f(x,y) subject to the constraint x^4+y^4=1.
Solution. First we will study the picture, that is we graph some level curves of f and graph the constrant curve.
> | with(plots): |
> | top:=plot((1-x^4)^(1/4),x=-1..1,color=blue,thickness=2): |
> | bot:=plot(-(1-x^4)^(1/4),x=-2..2,color=blue,thickness=2): |
> | cont:=contourplot(x+y^2, x=-2..2, y=-2..2, grid=[55,55],
contours=[-1,-1/2,0,1/2,1,1.5],color=black,thickness=2): |
> | display(cont,top,bot); |
Therefore we see that the minimum will occur at (-1,0) and that (1,0) will be a local minimum. The maximum will occur near the right two "corners."
Now we are ready to proceed.
> | with(Student[MultivariateCalculus]): |
> |
> | LagrangeMultipliers(x+y^2,[x^4+y^4-1],[x,y]); |
What does this mean? We have five pairs of x & y values in brakets. At [-1,0] we get f(-1,0)=-1 which is absolute minimum. At [1,0] we get f(1,0)=1. This is a local minimum. The third pair means the x will be the roots of x^2+1=0 and y=0. But there are no real solutions. (I don't know why Maple uses _Z instead of x.) The next pair says x is any of the zeros of x^4+4x^6-1=0. We can use fsolve to estimate the solutions.
> | fsolve(x^4+4*x^6=1,x); |
The other half of the pair means y is any of the solutions to y^2=2x^3. For x<0 there are no real solutions. For x=0.7461186870 we get y= +/- 0.911437459. These coordinates give the asbsolute maximum value for f(x,y) subject to the constraint. It is f=1.576836929.
Another method!
y^4 = 1-x^4 so y^2 = sqrt(1-x^4). Thus f(x,y(x)) = x + sqrt(1-x^4).
> | diff( x + sqrt(1-x^4),x); |
Set this equal to zero. Then sqrt(1-x^4) = 2x^3. This gives 4x^6+x^4-1 = 0. As before we can solve this with fsolve. But we lost the (-1,0) & (1,0) solutions! Where did they go? Study the graphs any see if you cn figure that out.