Python: How to graph $y^2=x^3-7+3$?
I have been searching online but I can't find a way to do it.
Python: How to graph $y^2=x^3-7+3$?
I have been searching online but I can't find a way to do it.
Matplotlib's contour
function can be used to plot the solution to implicit equations:
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
y, x = np.ogrid[-4:4:1000j, -6:6:1000j]
plt.contour(
x.ravel(), y.ravel(), y**2 - x**3 + 7*x -3, [0])
plt.show()
yields
With matplotlib
and numpy
:
import matplolib.pyplot as plt
import numpy as np
from math import sqrt
x = np.arange(10,100) # You have to choose the domain you are looking to plot
y = [sqrt(i**3 - 7 + 3) for i in x]
plt.plot(x,y)
plt.show()
Well, actually you have to be careful with the domain of the function, in order to choose +sqrt
or -sqrt
.