Chapter 4: Partial Differentiation
Section 4.9: Constrained Optimization
Example 4.9.6
Find the point on the curve x2y−4=1 that is closest to the point 4,5.
Solution
Mathematical Solution
The distance from the point 4,5 to the graph of x2y−4=1 is given by d=x−42+1−1/x22, after solving the constraint for y=yx.
The objective function will be taken as fx,y=x−42+y−52, the square of the distance from the point 4,5 to the constraint curve defined by gx,y=x2y−4−1=0.
The vertical line x=0 (i.e., the y-axis) is a vertical asymptote for the constraint curve. Maple will find the shortest distance from 4,5 to either branch of this curve, but it suffices to find the minimum on the branch in the first quadrant.
Figure 4.9.6(a) shows level curves of f in black, and the graph of g=0, in red.
The point where the red curve is tangent to a circle minimizes f at 0.8780294598, so d≐0.937.
The slider in Figure 4.9.6(b) controls the value of the x-coordinate so that under the slider, the companion value of d appears.
The green line-segment connects 4,5 to the selected point on the constraint curve.
use plots in module() local p1,p2,p3; p1:=contourplot((x-4)^2+(y-5)^2,x=2..6,y=3..7,color=black,contours=[.5,0.8780294598,1.5,2,3,4]); p2:=plot(4+1/x^2,x=2..6,color=red); p3:=display(p1,p2,scaling=constrained); print(p3); end module: end use:
Figure 4.9.6(a) Level curves of f and g=0
x = =
d =
Figure 4.9.6(b) Slider-controlled x and dx
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⁢y−4+1,−2⁢x⁢y−4⁢λ+2⁢x−8,−λ⁢x2+2⁢y−10
An exact solution of these equations is not possible, so numeric algorithms give the two solutions
x,y≐3.97,4.06, with λ≐−0.119, f≐0.878, and d≐0.937
and
x,y≐−0.725,5.90, with λ≐3.43, f≐23.14, and d≐4.81
Maple Solution - Interactive
Initialize
Tools≻Load Package: Student Multivariate Calculus
Loading Student:-MultivariateCalculus
Context Panel: Assign Name
f=x−42+y−52→assign
g=x2⋅y−4−1→assign
Apply the LagrangeMultipliers command in the Student MultivariateCalculus package, captured in the task template. See Table 4.9.6(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.6(a) The Lagrange Multiplier Method task template
Two local minima have been found, one on the branch of g=0 in the first quadrant, and one on the branch in the second quadrant.
Clearly, the local minimum on the branch in the first quadrant is closer to 4,5, so d=0.8780294598≐0.937 is also the global minimum, occurring at approximately 3.97,4.06.
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.6(b) shows the Optimization Assistant finding the minimum of 0.878 at 3.97,4.06.
Figure 4.9.6(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: Solve≻Numerically Solve
F
−x2⁢y−4−1⁢λ+x−42+y−52
→gradient
→to list
−x2⁢y−4+1,−2⁢x⁢y−4⁢λ+2⁢x−8,−λ⁢x2+2⁢y−10
→solve
λ=−0.1188413057,x=3.970065657,y=4.063446055
Maple Solution - Coded
Install the Student MultivariateCalculus package.
withStudent:-MultivariateCalculus:
Define f, the objective function.
f≔x−42+y−52:
Define g, the constraint function.
g≔x2⋅y−4−1:
Implement the Lagrange multiplier method
Invoke the LagrangeMultipliers command from the Student MultivariateCalculus package. Maple returns multiple solutions, some of which are complex; apply the remove and has commands to discard the complex solutions.
removehas,LagrangeMultipliersf,g,x,y,I
3.970065657,4.0634460,−0.7252400916,5.901237588
Add the "detailed" option to the LagrangeMultipliers command. Use the print command and the tilde operator to display the solutions one above the other.
S≔removehas,LagrangeMultipliersf,g,x,y,output=detailed,I:print~S
x=3.970065657,y=4.0634460,λ1=−0.11884131,x−42+y−52=0.8780294598
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.
fsolveEquateGradientF,x,y,λ,0,0,0,x,y,λ
The fsolve command solves equations numerically. Here, it has found the solution in the first quadrant. To find the other real solution, the command requires additional information. For example, to find the solution in the second quadrant, use the following version of the command.
fsolveEquateGradientF,x,y,λ,0,0,0,x=−1,y=6,λ
λ=3.426933557,x=−0.7252400916,y=5.901237588
<< 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