2

I would like to draw the curve a generic cubic function using matplotlib. I want to draw curves that are defined by functions such as: x^3 + y^3 + y^2 + 2xy^2 = 0. Is this possible to do?

2
  • Here is what helped me stackoverflow.com/questions/12935098/… Commented Oct 17, 2013 at 9:26
  • ^Not quite what i'm looking for, but thank you! Commented Oct 17, 2013 at 9:27

2 Answers 2

4

One obvious way to do this is to found the (x,y) pairs satisfy the relationship, by numerically solving the equation.

from scipy import optimize
f=lambda x, y: (x**3+y**3+y**2+2*x*y*y-0)**2
y_range=linspace(-1, 1, 100)
x_range=[optimize.fmin(f,0,args=(y,), disp=0) for y in y_range]
xr=linspace(-1,1)
yr=linspace(-1,1)
X, Y=meshgrid(xr, yr)
Z=f(X, Y)
plt.plot(x_range, y_range, 'k')
plt.contourf(xr, yr, Z, levels=linspace(0,0.001,51), alpha=0.5)
plt.colorbar()

enter image description here

The black line is what you want. The contour is just to show how the function behaves around 0. optimize.fmin() is not the most efficient solver here, just keep it simple.

When the absolute values of x or y are large, you are essentially plotting x+0.4496y=0 and you don't need to do all these above.

Sign up to request clarification or add additional context in comments.

Comments

0

my 2 cents:
x^3+y^3+y^2+2xy^2=0
y^2=-x^3-y^3-2xy^2
y^2>0 => -x^3-y^3-2xy^2>0 => x^3+y^3+2xy^2<0 =>
x(x^2+2y^2)+y^3<0 => x(x^2+2y^2)<-y^3 => (x^2+2y^2)<-y^3/x
0<(x^2+2y^2) => 0<-y^3/x => 0>y^3/x =>
(x>0 && y<0) || (x<0 && y>0)
your graph will span across the 2nd and 4th quadrants

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.