Reputation: 23
I need to plot an hyperbola of the type (y-ax)(y-bx)=-1 with matplotlib, I've tried to express y(x) but it gives an sqrt with impossible values. How can I assign to y the values to be plotted?
The function i want to plot is
$$(y-\log(r^a 10^c))(y-\log(r^b10^d))=-1$$
which I "can" be rewritten as
$$y=1/2[log(r^(a+b)10^(c+d))\pm\sqrt{-4+\log^2(r^(a-b)10^(c-d))}]$$
Upvotes: 0
Views: 2769
Reputation: 80289
With sympy, Python's symbolic math library, that builds on matplotlib to directly plot an implicit curve.
from sympy import plot_implicit, Eq
from sympy.abc import x, y
a = -1
b = 3
plot_implicit(Eq((y - a * x) * (y - b * x), -1), (x, -10, 10), (y, -10, 10))
The other equation could be plotted as follows, provided you rename x
to r
and have interesting values for the parameters and limits.
from sympy import plot_implicit, Eq, log
from sympy.abc import x, y
a = ...
b = ...
c = ...
d = ...
eq1 = Eq ((y- log(x**a * 10**c))*(x-log(x**b * 10*d)), -1)
plot_implicit(eq1, (x, -100, 100), (y, -100, 100))
Upvotes: 1