Is there an easy way to get all function breaks in some area with sympy?

Given the expression in sympy, is there a way to find all the gaps in a given interval? For example, if 1 / (x ^ 2-1) is from -2 to 2, it will return -1 and 1. This does not have to be symbolic. A numerical solution can really work better for my purposes.

+4
source share
2 answers

You can use the module for this singularities.

In [ ]: from sympy import *  
In [ ]: init_printing()
In [ ]: x = symbols('x')
In [ ]: singularities(1/(x**2 - 1), x)
Out[ ]: (-1, 1) # A tuple of SymPy objects

Link: http://docs.sympy.org/latest/modules/calculus/index.html#sympy.calculus.singularities.singularities

+2
source

, SymPy - : (.. , ).

, , , .

>>> expr
1/(x**2 - 1)
>>> n, d = expr.as_numer_denom()
>>> sympy.solve(d)
[-1, 1]

:

>>> expr2 = 1/(sympy.sin(x)) + 4/(x**2 - 3)
>>> expr2
1/sin(x) + 4/(x - 3)
>>> n, d = expr2.as_numer_denom()
>>> sympy.solve(d)
[0, -sqrt(3), sqrt(3), pi]

, SymPy pi ; , .

+2

Source: https://habr.com/ru/post/1621338/


All Articles