14.8: Lagrange Multipliers
Andy Long
MAT329, Fall, 2015

Example 2, p. 984:

f[x_,y_]:=x^2+2y^2
Plot3D[f[x,y],{x,-2,2},{y,-2,2}]
p1=ContourPlot[f[x,y],{x,-2,2},{y,-2,2},Contours->10];
p2=Plot[{Sqrt[1-x^2],-Sqrt[1-x^2]},{x,-2,2}];
Show[p1,p2]

g[x_,y_]:=x^2+y^2
fx[x_,y_]=D[f[x,y],x]
fy[x_,y_]=D[f[x,y],y]
gx[x_,y_]=D[g[x,y],x]
gy[x_,y_]=D[g[x,y],y]
Solve[g[x,y]==1&&fx[x,y]==a*gx[x,y]&&fy[x,y]==a*gy[x,y],{x,y,a},Reals]

Example (of my own): don’t forget lambda=0

f[x_,y_]:=E^(-(x y -1)^2)
Plot3D[f[x,y],{x,-2,2},{y,-2,2}]
p1=ContourPlot[f[x,y],{x,-2,2},{y,-2,2}];
p2=Plot[{Sqrt[4-x^2],-Sqrt[4-x^2]},{x,-2,2}];
Show[p1,p2]

g[x_,y_]:=x^2+y^2
fx[x_,y_]=D[f[x,y],x]
fy[x_,y_]=D[f[x,y],y]
gx[x_,y_]=D[g[x,y],x]
gy[x_,y_]=D[g[x,y],y]
Solve[g[x,y]==4&&fx[x,y]==a*gx[x,y]&&fy[x,y]==a*gy[x,y],{x,y,a},Reals]

Solve[x^4-4x^2+1==0,x,Reals]

xs={ -Sqrt[2 - Sqrt[3]],Sqrt[2 - Sqrt[3]],  -Sqrt[2 + Sqrt[3]],Sqrt[2 + Sqrt[3]]};
ys=1/xs;
p3=ListPlot[Transpose[{xs,ys}],PlotMarkers->{Automatic,Large}];
Show[p1,p2,p3]

Plot[f[2Cos[th],2Sin[th]],{th,0,2Pi}]