Chapter 4: Partial Differentiation
Section 4.9: Constrained Optimization
Example 4.9.7
Find the point on the surface x⁢y+3−z=0 that is closest to the point 2,7,5.
Solution
Mathematical Solution
The objective function should be
x−22+y−72+z−52
but taking the objective function f as the square of this leads to much simpler algebra.
The constraint is
gx,y,z≡x y+3−z=0
In Figure 4.7.7(a), the sphere of approximate radius 1.695, the level surface f≐2.874, is tangent to the constraint surface g=0, drawn in red.
use plots,plottools in module() local p1,p2,p3; p1:=sphere([2,7,5],1.695280608); p2:=plot3d(x*y+3,x=0..4,y=5..9,color=red); p3:=display(p1,p2,scaling=constrained,labels=[x,y,z],axes=frame,orientation=[-70,85,0],tickmarks=[5,5,5],view=[0..4,5..9,3..7],lightmodel=none); print(p3); end module: end use:
Figure 4.9.7(a) Level surface of f and g=0
To implement the Lagrange multiplier technique, solve ∇f=λ ∇g, and the constraint g=0, for the four unknowns x,y,z,λ.
The resulting equations are
−x⁢y+z−3,−λ⁢y+2⁢x−4,−λ⁢x+2⁢y−14,λ+2 z−10
with solution P:x,y,z≐0.32,6.92,5.24 when λ≐−0.484, so that fP≐2.874.
The minimum distance from 2,7,5 to the constraint surface is therefore 2.874≐1.695.
Maple Solution - Interactive
Initialize
Tools≻Load Package: Student Multivariate Calculus
Loading Student:-MultivariateCalculus
Context Panel: Assign Name
f=x−22+y−72+z−52→assign
g=x⁢y+3−z→assign
Apply the LagrangeMultipliers command in the Student MultivariateCalculus package, captured in the task template. See Table 4.9.7(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.7(a) The Lagrange Multiplier Method task template
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.7(b) shows the Optimization Assistant finding the minimum of 2.87 at
0.32,6.92,5.24
Figure 4.9.7(b) 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
−x⁢y−z+3⁢λ+x−22+y−72+z−52
→gradient
→to list
−x⁢y+z−3,−λ⁢y+2⁢x−4,−λ⁢x+2⁢y−14,λ+2⁢z−10
→solve
λ=−0.4843021234,x=0.3239373254,y=6.921558233,z=5.242151062
Maple Solution - Coded
Install the Student MultivariateCalculus package.
withStudent:-MultivariateCalculus:
Define f, the objective function.
f≔x−22+y−72+z−52:
Define g, the constraint function.
g≔x⁢y+3−z:
Implement the Lagrange multiplier method
Invoke the LagrangeMultipliers command from the Student MultivariateCalculus package. In addition to the one real solution, there are multiple complex solutions. Apply the remove and has commands to filter out the complex solutions.
removehas,LagrangeMultipliersf,g,x,y,z,I
0.3239373254,6.921558232,5.242151062
Add the "detailed" option to the LagrangeMultipliers command.
removehas,LagrangeMultipliersf,g,x,y,z,output=detailed,I
x=0.3239373254,y=6.921558232,z=5.242151062,λ1=−0.4843021234,x−22+y−72+z−52=2.873976339
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 the real solution of the equations in ∇f−λ ∇g=0.
fsolveEquateGradientF,x,y,z,λ,0,0,0,0,x,y,z,λ
<< 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