I am trying to learn multivariate optimisation and was trying to plot a graph of $2x^2 y^2$ vs a plane which is restricted between (-1,1) - essentially a square. This is the code snippet for the same
import sympy as sp
x,y = sp.symbols('x y')
paraboloid = sp.lambdify((x,y),2*(x**2) y**2)
plane = sp.lambdify((x,y),2*x 3*y 4)
plane2 = sp.lambdify((x,y),x y)
import numpy as np
points = np.arange(-5,5,0.1)
x,y = np.meshgrid(points,points)
points2 = np.arange(-1,1,0.1)
x2,y2 = np.meshgrid(points2,points2)
import plotly.graph_objects as go
fig = go.Figure(data = [go.Surface(z = paraboloid(x,y)),go.Surface(z = 5 0*plane2(x2,y2))])
fig.update_traces(contours_z=dict(show=True, usecolormap=True,
highlightcolor="limegreen", project_z=True))
fig.show()
The output is as follows: Plotly Output
Now I have 2 questions:
- Shouldn't the minima of the paraboloid be at 0,0 where as it is actually coming out to be a maxima
- Why is my plane not exactly below the paraboloid
I think these are related questions so if one gets answered other gets answered. Requesting your help. The Stack platform didn't let me put image inline so the output image is attached, apologies for inconvenience.
CodePudding user response:
I think that you need to explicitly specify the x and y axis in the data:
data = [
go.Surface(z = paraboloid(x,y), x=x, y=y),
go.Surface(z = 5 0*plane2(x2,y2), x=x2, y=y2)
]
it is mentioned in the documentation :
Passing x and y data to 3D Surface Plot If you do not specify x and y coordinates, integer indices are used for the x and y axis. You can also pass x and y values to go.Surface.