multiplicadores de lagrange matlab
TRANSCRIPT
-
7/21/2019 Multiplicadores de Lagrange Matlab
1/4
Graphical-Numerical
Optimization Methods
and Lagrange Multipliers
copyright 2000 by Paul Green and Jonathan Rosenberg
Constrained Extremal Problems in Two ariablesIn this notebook, we will examine the problem of finding the extreme values of a function
on a bounded region. We will start by finding the extreme values of the function4422
4), yxyxyxf ++= on the region 42),22
+= yx eeyxg . !xtreme values can
occur either at critical points offinterior to the region, or along the boundary. What we
must do, therefore, is evaluatefat those critical points that satisfy the ine"uality definingthe region, and compare those values to the maximum and minimum along the boundary.
We will find the latter by using the method of #agrange multipliers. We begin by
defining the functionsfandgin $%%'.
syms x y z
f=4-x^2-y^2+x^4+y^4
g=exp(x^2)+2*exp(y^2)
(ext, we find the critical points off. or reasons that will become apparent later, weinclude the derivative offwith respect toz, even though it is identically * sincefdoes not
depend onz.
gradf=jacobian(f,[x,y,z])
[xfcri,yfcri]=so!"e(gradf(#),gradf(2))$
[xfcri,yfcri]
(ext, we evaluategat the critical points to determine which of them are in the region.
gf%n=in!ine("ecorize(g))
do%b!e(gf%n(xfcri,yfcri))
We see that only the first three critical points are in the region. +onse"uently we are onlyinterested in the values offat those points.
ff%n=in!ine("ecorize(f))
ff%n(xfcri([#,2,&]),yfcri([#,2,&]))
We must now address the problem of finding the extrema offon the boundary curve.
&he theory of #agrange multipliers tells us that the extreme values will be found at points
where the gradients offandgare parallel. &his will be the case precisely when the cross
-
7/21/2019 Multiplicadores de Lagrange Matlab
2/4
product of the gradients offandgis -ero. It is for this reason that we have defined the
gradient off, and will define the gradient ofg, to be formally threedimensional. We
observe that since the gradients offandglie in the plane spanned by iand j), only thethirdcomponent of the crossproduct,
fx)gy) fy)gx),
will ever be different from -ero. &his gives us a system of two e"uations, the solutions ofwhich will give all possible locations for the extreme values of fon the boundary.
gradg=jacobian(g,[x,y,z])
gradcross=cross(gradf,gradg)$
!agr=gradcross(&)
[xbo%ndcri,ybo%ndcri]=so!"e(g-4,!agr)
$%%' appears to have found a constrained critical point. /owever it cannot possibly
be the only one, sincefmust take both a maximum and a minimum along the curveg04.We shall have to resort to graphicalnumerical methods. We begin by using genplotto
plot the loci of the two e"uations we are trying to solve.
genp!o(g, -2'#'2,-2'#'2,cono%r,[4,4],r)$ o!d on$
genp!o(!agr, -2''2,-2''2,cono%r,[,],b)$ o!d off$
We see now that the critical point found by solveis one of eight. our of them are on the
axes, and can be easily be found analytically. &he other four will re"uire the use of the
root finder newton2d. #et us deal with the first four. We simply have to setxoryto -ero
and solve the e"uationg04 for the other. &his gives
xaxiscris=so!"e(s%bs(g-4,y,))$
[xaxiscris,[$]]
yaxiscris=so!"e(s%bs(g-4,x,))$
[[$],yaxiscris]
&he numerical values of these critical points are1do%b!e([xaxiscris,[$]])
do%b!e([[$],yaxiscris])
and the correspondingfvalues are1
do%b!e(ff%n(xaxiscris,[$]))
do%b!e(ff%n([$],yaxiscris))
&he remaining four constrained critical points seem to be near 2.*== yx .
[xb#,yb#]=neon2d(g-4,!agr,,)
-
7/21/2019 Multiplicadores de Lagrange Matlab
3/4
[xb2,yb2]=neon2d(g-4,!agr,-,)
[xb&,yb&]=neon2d(g-4,!agr,-,-)
[xb4,yb4]=neon2d(g-4,!agr,,-)
ff%n([xb#,xb2,xb&,xb4],[yb#,yb2,yb&,yb4])
We now see that the maximum value offin the region of interest is 4, at the interiorcritical point *,*), and the minimum value is 3.24, taken at the four points we 5ust
found. We can check this graphically by superimposing a contour plot offon a picture of
the bounding curve. (ote that we select only those contours offwith values close theones we want, in order to get the best possible picture, and have added the colorbar
command to add a legend indicating what colors correspond to whatfvalues.
genp!o(g, -2'#'2,-2'#'2,cono%r,[4,4],.)$ o!d on$
genp!o(f, -2''2,-2''2,cono%r,[&'#'42])$ o!d off$
co!orbar
Practice Problem! ind the minimum and maximum values of the function
yxyxyxf ++= 244 3), on the region defined by 3)sin), 22 =+= xyyxyxg
.
" Ph#sical "pplication/ere6s an example from "uantum mechanics that illustrates how the #agrange multiplier
method can be used. +onsider a particle of mass mfree to move along thexaxis, sittingin a 7potential well7 given by a potential energy function 8x) that tends to +as x . &hen the 7ground state7 of the particle is given by a 7wave function7 x), wherex)2 gives the probability of finding the function nearx. 9ince the total probability offinding the functionsomewhereis :, we have the constraint that x)2 dx 0 :. % basicprinciple of physics states that x)will be the function minimi-ing the energy, which isgiven by
!)0h22m)x)2 ; 8x)x)2 )dx,where his
-
7/21/2019 Multiplicadores de Lagrange Matlab
4/4
g=simp!e(in(pi^2,-inf,inf))
9o our constraint is g0:. (ow let6s compute the energy function. or convenience we6releaving out the factor of > in both terms inside the integral.)
piprime=simp!e(diff(pi))
energy=simp!e(in(piprime^2+x^4*pi^2,-inf,inf))
(ow we solve the #agrange multipler e"uations. &his time we have a function !a,b,c)that we need to minimi-e sub5ect to a constraint ga,b,c) 0 :, so the e"uations are
! g0 0.syms !am
eg=jacobian(energy,[a,b,c])$
gg=jacobian(g,[a,b,c])$
!agr=eg-!am*gg$
[aso!,bso!,cso!,!so!]=so!"e(g-#,!agr(#),!agr(2),!agr(&),a,b,c,!am)$
do%b!e([aso!,bso!,cso!,!so!])
+learly there6s some small imaginary roundoff error here. We can get rid of it by taking
the real parts1rea!(do%b!e([aso!,bso!,cso!,!so!]))
(ow we need to look for the minimum value of the energy1ef%n=in!ine("ecorize(energy))$
rea!(do%b!e(ef%n(aso!,bso!,cso!)))
&he minimum energy for this choice of the form of x) is thus :.*?::. We can plot the
probability density1bespi=s%bs(pi,[a,b,c],[aso!(&),bso!(&),cso!(&)])$ezp!o(bespi^2)$ i!e(probabi!iy densiy)
"dditional Problems
:. ind the minimum value of the function fx, y) 0 4 x2y2; x4; y4sub5ect to theconstraint gx, y) 0 x22x ; y23 *. @ou will find many interior critical points andmany solutions to the #agrange multiplier e"uations.
2. ind and plot the function x) of the same form as in the example above) minimi-ingthe energy for the potential 8x) 0 x2;x4)2, with the same constraint x)2 dx 0 :, and
compare the result with the example above. %gain take h0m0:.