Chapter 4: Partial Differentiation
Section 4.9: Constrained Optimization
Example 4.9.1
Find the extreme values of fx,y=2 x2+3 y2 subject to the constraint gx,y≡x2+⁢y2−1=0.
Solution
Mathematical Solution
Figure 4.9.1(a) shows the surface z=f and on it, the "lift" of the constraint curve g=0. From this figure, infer that there are four extrema, two maxima and two minima.
Figure 4.9.1(b) shows the level curves of f in black, and the curve defined implicitly by g=0, in red. The points of tangency between the constraint curve and a level curve of f defines a stationary point for the constrained optimization problem.
These stationary points occur where the gradients of f and g are collinear, that is, where ∇f is proportional to ∇g. The animation in Figure 4.9.1(c) shows these gradients traversing the constraint curve g=0. They become collinear at the four points of tangency that are the stationary points that the Lagrange multiplier method finds.
use plots in module() local p1,p2,p3,a; a:=1.37; p1:=plot3d(2*x^2+3*y^2,x=-a..a,y=-a..a,transparency=0,lightmodel=none); p2:=spacecurve([cos(t),sin(t),2*cos(t)^2+3*sin(t)^2],t=0..2*Pi,color=black,thickness=3); p3:=display(p1,p2,scaling=constrained,axes=frame,view=0..4,tickmarks=[3,3,5],labels=[x,y,z],orientation=[-35,70,0]); print(p3); end module: end use:
Figure 4.9.1(a) Constraint curve lifted to the surface f
use plots in E491:=module() local p1,p2,f,g; export p3; f:=2*x^2+3*y^2; g:=x^2+y^2-1: p1 := implicitplot(g=0,x=-1..1,y=-1..1, color=red): p2 := contourplot(f,x=-1.5..1.5,y=-1.2..1.2, contours=[1,2,3,4],color=black): p3:=display([p1,p2],tickmarks=[[-1,0,1],[-1,0,1]],scaling=constrained): print(p3); end module: end use:
Figure 4.9.1(b) f=c in black and g=0 in red
use Student:-VectorCalculus, plots in module() local p1,X; X:=proc(t) local Vf,Vg; Vf:=t->RootedVector(root=[cos(t),sin(t)],.7*<2*cos(t),3*sin(t)>); Vg:=t->RootedVector(root=[cos(t),sin(t)],<cos(t),sin(t)>); PlotVector([Vf(t),Vg(t)],color=[black,red]); end; p1:=animate(X,[t],t=0..2*Pi,frames=40,background=E491:-p3); print(p1); end module: end use:
Figure 4.9.1(c) ∇f and ∇g on g=0
The equations arising from ∇f−λ ∇g = 4 x6 y−λ 2 x2 y=00, and the constraint equation itself, are then
4 x−2 λ x=0,6 y− λ y=0,x2+y2=1
The first equation is satisfied if x=0 or λ=2. The second equation is satisfied if y=0 or λ=3.
If x=0, the third equation gives y=±1. If y=0, the third equation gives x=±1. Consequently, there are four solutions to these equations: 0,1,0,−1,1,0, and −1,0.
Maple Solution - Interactive
Initialize
Tools≻Load Package: Student Multivariate Calculus
Loading Student:-MultivariateCalculus
Context Panel: Assign name
f=2 x2+3 y2→assign
Context Panel: Assign Name
g=x2+y2−1→assign
Optimization Assistant
The Optimization Assistant is no longer listed in Tools≻Assistants. It is now found in Tools≻Tutors≻Optimization
A numeric solution and some useful graphics are available via the , launched from the Context Panel on the sequence f,g=0.
Each of the four extrema are found separately.
The first extrema, the minimum of 2 at x,y=1,0, is obtained by clicking on the Solve button. If the Plot button is next clicked, Figures 4.9.1(e, f) can be obtained. Note the modification of the plotting ranges.
A second minimum can be obtained by adding initial values for the numeric search. Click the Edit button at the right of "Initial Values" and provide x,y=−3,1 for new initial values. The search will now find the minimum 2 at −1,0.
Figure 4.9.1(d) Optimization Assistant
Figure 4.9.1(e) Surface, constraint, & minimum
Figure 4.9.1(f) Constraint as a surface
The maxima can be found by again adjusting the initial values.
Implement the Lagrange multiplier method via first principles
F=f−λ g→assign
Write F and press the Enter key.
Context Panel: Student Multivariate Calculus≻ Differentiate≻Gradient
Context Panel: Conversions≻To List
Context Panel: Solve≻Solve
F
−x2+y2−1⁢λ+2⁢x2+3⁢y2
→gradient
→to list
−x2−y2+1,−2⁢λ⁢x+4⁢x,−2⁢λ⁢y+6⁢y
→solve
λ=3,x=0,y=1,λ=3,x=0,y=−1,λ=2,x=1,y=0,λ=2,x=−1,y=0
The LagrangeMultipliers command in the Student MultivariateCalculus package is captured in the task template. Its use is illustrated in Table 4.9.1(a).
Tools≻Tasks≻Browse:
Calculus - Multivariate≻Optimization≻Lagrange Multiplier Method
Method of Lagrange Multipliers
Enter objective function f
Enter constraints gk=0,k=1,…,entered as functions g1,g2,…
Enter coordinate variables, separated by commas:
Table 4.9.1(a) The Lagrange Multiplier Method task template
Maple Solution - Coded
Install the Student MultivariateCalculus package.
withStudent:-MultivariateCalculus:
Define f, the objective function.
f≔2 x2+3 y2:
Define g, the constraint function.
g≔x2+y2−1:
Implement the Lagrange multiplier method
Invoke the LagrangeMultipliers command from the Student MultivariateCalculus package.
LagrangeMultipliersf,g,x,y0,1,0,−1,1,0,−1,0 ⇒
Add the "detailed" option to the LagrangeMultipliers command.
Apply the print command and tilde, the element-wise operator, to print the four solutions one under the other.
S≔LagrangeMultipliersf,g,x,y,output=detailed: print~S
x=0,y=1,λ1=3,2⁢x2+3⁢y2=3
Implement the Lagrange multiplier method from first principles
Define F.
F≔f−λ g:
Use the Gradient command to obtain ∇f−λ ∇g.
Use the Equate command to equate each component of ∇f−λ ∇g to zero.
Use the solve command to obtain the solutions of the equations in ∇f−λ ∇g=0.
solveEquateGradientF,x,y,λ,0,0,0,x,y,λ
x=0,y=1,λ=3,x=0,y=−1,λ=3,x=1,y=0,λ=2,x=−1,y=0,λ=2
The code in Table 4.9.1(b) will draw Figure 4.9.1(b).
use plots in p1 ≔ implicitplotg=0,x=−1..1,y=−1..1, color=red: p2 ≔ contourplotf,x=−1.5..1.5,y=−1.2..1.2, contours=1,2,3,4,color=black: displayp1,p2,tickmarks=−1,0,1,−1,0,1,scaling=constrained: end use:
Table 4.9.1(b) Code for generating Figure 4.9.1(a)
<< Chapter Overview Section 4.9 Next Example >>
© Maplesoft, a division of Waterloo Maple Inc., 2024. All rights reserved. This product is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation.
For more information on Maplesoft products and services, visit www.maplesoft.com
Download Help Document