While learning about Lagrange multipliers, I am finding examples on how a constraint is applied to a function.
Given the following two functions (where E^ is ::e::
):
f[x_, y_] := E^(-(3 x^2 + 2 y^2 - x y)/(3))
g[x_, y_] := x^2 + 2*(y + 1/2)^2 - 1
And the following constraint:
g[x,y]==0
I would like to get a plot of the path of the constraint g[x,y]
over the function f[x,y]
.
I have tried to plot the function f[x,y] with:
f3d = Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}]
Which results in:
And I would like to see the path of the constrain g[x,y]==0
over that surface. Similar to this example:
ContourPlot3D[{x^2 + y^2 + z^2 - 4, (x - 1)^2 + y^2 - 7/8}, {x, -2,
2}, {y, -2, 2}, {z, -2, 2}, ContourStyle -> {Automatic, Opacity[0]},
Mesh -> None,
BoundaryStyle -> {2 -> None, {1, 2} -> {Green, Thick, Dashed}}]
But I can not get that plot. I have tried this but I am missing the condition g[x,y]==0
which I do not know how to add:
ContourPlot3D[f[x, y] == g[x, y], {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]
In 2D is easier as you can draw both contour plots and then combine, but in 3D I do not know how to do it.