Minimize the function \(f(x)=2x^2+y^2\) subject to the constraint
\( x^2+y^2=1 \)
We start with a picture, that shows the surface defined by \(z=f(x,y)\),
the constraint \( x^2+y^2=1 \) and the constrained points on the surface
(%i6) | load(draw)$ |
(%i2) | fsurf: explicit( 2*x^2 + y^2,x,-1.5,1.5,y,-1.5,1.5); |
(%i3) | cons: parametric(cos(t),sin(t),0,t,0,2*%pi); |
(%i4) | fcons: parametric(cos(t),sin(t),2*cos(t)^2 + sin(t)^2,t,0,2*%pi); |
--> |
wxdraw3d(zrange=[0,2.5],fsurf,line_width=3,color=red,cons, color=black,line_width=3,fcons); |
Now for the Lagrange multiplier calculation:
--> | f: 2*x^2+y^2; |
--> | g: x^2+y^2; |
--> | solve([diff(f,x)=h*diff(g,x),diff(f,y)=h*diff(g,y),g=1],[x,y,h]); |
We could also solve for the constraint:
--> | s: solve(g=1,y); |
--> | fx1: ev(f,y=rhs(s[1])); |
--> | fx2: ev(f,y=rhs(s[2])); |
--> | solve(diff(fx1,x),x); |
And of course we need to consider the endpoints of the interval of possible \(x\) values: \( x=\pm 1 \), and we see the solution by this method agrees with the Lagrange method above.
Now for a 3D example with Lagrange Multiplier
Minimize the Surface area of a rectangular prism subject to the
volume constraint \( xyz=1000 \).
--> | A: 2*x*y + 2*y*z+2*z*x; |
--> | V: x*y*z; |
--> | eq1: diff(A,x)=h*diff(V,x); |
--> | eq2: diff(A,y)=h*diff(V,y); |
--> | eq3: diff(A,z)=h*diff(V,z); |
--> | eq4: V=1000; |
--> | solve([eq1,eq2,eq3,eq4],[x,y,z,h]); |
But now a closely related problem that doesn't work so well
with the solver:
Minimize the volume of a rectangular prism subject to
the surface area constraint \( 2yz+2xz+2xy=12 \)
--> | A: 2*y*z + 2*x*z + 2*x*y; |
--> | V(x,y,z):=x*y*z; |
--> | eq1: diff(V(x,y,z),x)=h*diff(A,x); |
--> | eq2: diff(V(x,y,z),y)=h*diff(A,y); |
--> | eq3: diff(V(x,y,z),z)=h*diff(A,z); |
--> | eq4: A=12; |
--> | solve([eq1,eq2,eq3,eq4],[x,y,z,h]); |
Eeek! Langrange Multipliers didn't yield a solution.
Try substituting the constraint into the function to be optimized:
--> | s: solve(A=12,z); |
--> | s[1]; |
--> | rhs(s[1]); |
--> | Vxy: ev(V,z=rhs(s[1])); |
--> | solve([diff(Vxy,x),diff(Vxy,y)],[x,y]); |
If we ignore the unfeasible solutions (non-postive reals and imaginaries), we have \( x=\sqrt{2}, y=\sqrt{2} \)