Why my graph is showing incorrect minima, using np.linspace or np.array and poorly?

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:

  1. Shouldn’t the minima of the paraboloid be at 0,0 where as it is actually coming out to be a maxima
  2. 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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x