Chapter 4: Partial Differentiation
Section 4.9: Constrained Optimization
Example 4.9.8
Find the point(s) on the the curve x2+2⁢x y+3 y2=5 closest to, and farthest from, the point 1,2.
Obtain a graph of the level curves of the objective function fx,y, and on this graph superimpose the graph of the constraint curve.
Solution
Mathematical Solution
The distance from the point 1,2 to the graph of x2+2⁢x y+3 y2=5 is given by d=x−12+y−22, where y=yx along the constraint curve.
The objective function will be taken as fx,y=x−12+y−22, the square of the distance from the point 1,2 to the constraint curve defined by gx,y=x2+2⁢x y+3 y2−5=0.
Figure 4.9.8(a) shows level curves of f in black, and the graph of g=0, in red.
The constraint curve is tangent to a level curve at the four points listed in Table 4.9.8(a), a table that also gives approximate values of f and d at the critical points.
Critical Point
f
d
2.27,−1.48
13.715
3.7034
0.6,1.06
1.0442
1.02185
−0.17,−1.23
11.8137
3.4371
−2.69,0.65
15.4267
3.9277
Table 4.9.8(a) Extrema given approximately
use plots in module() local p1,p2,p3; p1:=contourplot((x-1)^2+(y-2)^2,x=-3..3,y=-2..4,color=black,contours=[.5,1.0442,2,4,7,10,11.8137,13.715,15.4267]); p2:=implicitplot(x^2+2*x*y+3*y^2-5 = 0,x=-3..3,y=-2..2,color=red); p3:=display(p1,p2,scaling=constrained); print(p3); end module: end use:
Figure 4.9.8(a) Level curves of f and g=0
The Lagrange multiplier method finds extrema by determining points of tangency between the constraint curve and the level curves of the objective function f by finding points where the gradients ∇f and ∇g are collinear. This is done by solving the equations ∇f=λ ∇g and g=0 for x,y,λ. The resulting equations are
−x2−2⁢x⁢y−3⁢y2+5,−2⁢x+2⁢y⁢λ+2⁢x−2,−2⁢x+6⁢y⁢λ+2⁢y−4
An exact solution of these equations is not possible, so numeric algorithms give the four solutions summarized in Table 4.9.8(a).
Maple Solution - Interactive
Initialize
Tools≻Load Package: Student Multivariate Calculus
Loading Student:-MultivariateCalculus
Context Panel: Assign Name
f=x−12+y−22→assign
g=x2+2⁢x y+3 y2−5→assign
Optimization Assistant
The Optimization Assistant is no longer listed in Tools≻Assistants. It is now found in Tools≻Tutors≻Optimization
A numeric solution is available via the , launched from the Context Panel on the sequence f,g=0.
Figure 4.9.8(b) shows the Optimization Assistant finding the absolute minimum.
Figure 4.9.8(c) shows the Optimization Assistant finding the absolute maximum.
Figure 4.9.8(b) Constrained minimum
Figure 4.9.8(c) Constrained maximum
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: Assign to a Name≻Q
F
−x2+2⁢x⁢y+3⁢y2−5⁢λ+x−12+y−22
→gradient
→to list
−x2−2⁢x⁢y−3⁢y2+5,−2⁢x+2⁢y⁢λ+2⁢x−2,−2⁢x+6⁢y⁢λ+2⁢y−4
→assign to a name
Q
Type Q and press the Enter key for a display of the Lagrange multiplier equations.
Context Panel: Solve≻Numerically Solve (for the first solution)
Context Panel: Solve≻Numerically Solve from point (solutions 2 - 4) (Select starting values gleaned from Figure 4.9.8(a).)
→solve
λ=0.8358039569,x=−0.1735542040,y=−1.230548031
λ=−0.2475484182,x=0.5904844352,y=1.063800281
λ=1.605494465,x=2.269870179,y=−1.478917481
λ=1.806249996,x=−2.686800410,y=0.6456652305
Maple Solution - Coded
Install the Student MultivariateCalculus package.
withStudent:-MultivariateCalculus:
Define f, the objective function.
f≔x−12+y−22:
Define g, the constraint function.
g≔x2+2⁢x y+3 y2−5:
Implement the Lagrange multiplier method
Invoke the LagrangeMultipliers command from the Student MultivariateCalculus package. The exact forms of the solutions are exceedingly large and cumbersome. Immediately float these expressions with the evalf command, which, unfortunately, generates numbers with a small imaginary part. Remove these small imaginary parts by applying simplify to the result of using the fnormal command. Use the print command and the tilde operator to display the solutions one above the other.
temp≔evalfLagrangeMultipliersf,g,x,y:Se≔simplifyfnormaltemp: print~Se
2.269870180,−1.478917496
Add the "detailed" option to the LagrangeMultipliers command. The exact forms of the solutions are exceedingly large and cumbersome. Immediately float these expressions with the evalf command, which, unfortunately, generates numbers with a small imaginary part. Remove these small imaginary parts by applying simplify to the result of using the fnormal command. Use the print command and the tilde operator to display the solutions one above the other.
temp≔evalfLagrangeMultipliersf,g,x,y,output=detailed: Sn≔simplifyfnormaltemp,9:print~Sn
x=2.26987018,y=−1.47891750,λ1=1.60549447,x2−2.⁢x+5.+y2−4.⁢y=13.7154372
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 fsolve command to obtain a numeric solution of the equations in ∇f−λ ∇g=0. Use the avoid option to obtain four different solutions.
s1≔fsolveEquateGradientF,x,y,λ,0,0,0,x=−1,y=6,λ
s2≔fsolveEquateGradientF,x,y,λ,0,0,0,x=−1,y=6,λ,avoid=s1
s3≔fsolveEquateGradientF,x,y,λ,0,0,0,x=−1,y=6,λ,avoid=s1,s2
s4≔fsolveEquateGradientF,x,y,λ,0,0,0,x=−1,y=6,λ,avoid=s1,s2,s3
Obtain λ,f and d at each critical point
evalλ,s1 = −0.2475484182
evalf,s1 = 1.044172912
evalf,s1 = 1.021847793
evalλ,s2 = 1.605494465
evalf,s2 = 13.71543711
evalf,s2 = 3.703435852
evalλ,s3 = 0.8358039569
evalf,s3 = 11.81367005
evalf,s3 = 3.437101984
evalλ,s4 = 1.806249996
evalf,s4 = 15.42671993
evalf,s4 = 3.927686333
<< Previous Example 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