


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



2
2
2
2
In[1]:= f = H x - 2 L ^ 2 + H y - 3 L ^ 2; g = H x - 4 L ^ 2 + H y - 5 L ^ 2 - 6;
LagrangianFunction = f + u *** H** g + s ^ 2 L
Out[2]= H- 2 + xL
2
2
2
2
M + H- 3 + yL
2
In[3]:= GradLF = D @ LagrangianFunction, 88 x, y, u, s <<D ;
GradLF êê MatrixForm
Out[4]//MatrixForm=
i
k
j j j j j j j j j j j j j j j
2 u H- 4 + xL + 2 H- 2 + xL
2 u H- 5 + yL + 2 H- 3 + yL
2
2
2
2 s u
y
z z z z z z z z z z z z z z z
In[5]:= eqns = Thread @ GradLF ä 8 0, 0, 0, 0 <D
Out[5]= 9 2 u H- 4 + xL + 2 H- 2 + xL ä 0, 2 u H- 5 + yL + 2 H- 3 + yL ä 0, - 6 + s
2
2
2
ä 0, 2 s u ä 0 =
In[6]:= FindRoot @ eqns, 8 x, 0 < , 8 y, 0 < , 8 u, 1 < , 8 s, 1 <D
Out[6]= 9 x Æ 2.26795, y Æ 3.26795, u Æ 0.154701, s Æ -1.91617 ¥ 10
=
23
Problem 2
2
In[7]:= f = H x - 2 L ^ 2 + H y - 3 L ^ 2; h = H x - 4 L ^ 2 + H y - 5 L ^ 2 - 6;
LagrangianFunction = f + v ***** h
Out[8]= H- 2 + xL
2
2
2
M + H- 3 + yL
2
In[9]:= GradLF = D @ LagrangianFunction, 88 x, y, v <<D ;
GradLF êê MatrixForm
Out[10]//MatrixForm=
i
k
j j j j j j j j jj
2 v H- 4 + xL + 2 H- 2 + xL
2 v H- 5 + yL + 2 H- 3 + yL
2
2
y
z z z z z z z z zz
In[11]:= eqns = Thread @ GradLF ä 8 0, 0, 0 <D
Out[11]= 9 2 v H- 4 + xL + 2 H- 2 + xL ä 0, 2 v H- 5 + yL + 2 H- 3 + yL ä 0, - 6 + H- 4 + xL
2
2
ä 0 =
In[12]:= FindRoot @ eqns, 8 x, 0 < , 8 y, 0 < , 8 v, 0 <D
Out[12]= 8 x Æ 2.26795, y Æ 3.26795, v Æ 0.154701<
In[13]:= FindRoot @ eqns, 8 x, 10 < , 8 y, 10 < , 8 v, 0 <D
Out[13]= 8 x Æ 5.73205, y Æ 6.73205, v Æ -2.1547<
In[18]:= Show @
ContourPlot @ h, 8 x, - 2, 10 < , 8 y, - 2, 10 < , Contours Æ 8 0 < ,
Axes -> True, Frame Æ False, AxesLabel Æ 8 "x", "y" < ,
ContourShading Æ 8 White, White < , ContourStyle Æ 8 Black, Thick <D ,
ContourPlot @ f, 8 x, - 2, 10 < , 8 y, - 2, 10 < , Contours Æ 8 0.14, 3, 10, 27.8, 50 < ,
Axes -> True, Frame Æ False, AxesLabel Æ 8 "x", "y" < ,
ContourShading Æ False, ContourStyle Æ Directive @ Blue, Dashed D ,
ContourLabels Æ Function @8 x, y, z < , Text @ Framed @ z D , 8 x, y < , Background Æ White DDD< ,
Epilog Æ 8
Text @ Style @ " H x - 4 L ^2 +H y - 5 L ^2 - 6 = 0", Medium, Bold D , 8 5.5, 2.2 <D ,
Disk @8 2.27, 3.27 < , 8 .2, .2 <D ,
Disk @8 5.73, 6.73 < , 8 .2, .2 <D<
Out[18]=
3
10
50
50
x
2
4
6
8
10
y