I have a task to plot grafic of function with asymptotes using Sympy, Numpy and Pyplot. My function is f(x) = (x^3 + 3 * x^2 - 2 * x - 2) / (2 - 3 * x^2)
. I found that vertical asymptotes are in x = -sqrt(6)/3
and x = sqrt(6)/3
, that means that f(sqrt(6)/3) = oo
. But F(-np.sqrt(6)/3)
returns 2451449131743593.0
, not infinity. Why? Also, MatLab gives me the same result, but f(-np.sqrt(6)/3) = oo * sqrt(6) = 2451449131743593
.
Asked
Active
Viewed 225 times
1

Adriaan
- 17,741
- 7
- 42
- 75

Maksym Andreiev
- 35
- 4
-
8Because floating point math. `sqrt(6)/3` is an irrational number. It can't be represented, in binary OR decimal. Even without binary getting in the way, the result is always going to be an approximation. The more math you do with that value, the more rounding errors you introduce. – Tim Roberts Dec 15 '21 at 19:12
-
1[See more about floats](https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate#:~:text=Because%20often%2Dtimes%2C%20they%20are,many%20digits%20in%20any%20base.) – 12944qwerty Dec 15 '21 at 19:19
-
3SymPy can represent the number `sqrt(6)/3` exactly so if you use sympy then `f(sqrt(6)/3)` gives `zoo` (complex infinity). – Oscar Benjamin Dec 15 '21 at 20:59