문제

I'm using sympy python library in order to get differentials, integrals, and functions evaluation. However, when it comes to certain cases like division by 0, naturally some cases will evaluate Infinity or some will just fail.

I've seen Infinity and NaN obtained in such error prone situations. I want to make sympy automatically raise an exception when it deals with such.

Basically I evaluate in two different states, one very simple:

fp = fx.subs(x,p)

Where fx is a symbolic expression (fx=S(fx)) and p a float.

Also I evaluate in this syntax like statements:

for x_i in xs:
    ys.append(float(fx.subs(x,x_i)))

Where xs and ys are lists and so x_i is a float.

In first statement raising an expception would come after evaluating obtained value, and so in second case. But how to avoid doing this manually? I think is better to set sympy or python environment to treat Infinity or NaN especially.

도움이 되었습니까?

해결책

I'm not clear what you are asking, but you can check if an expression has an infinity with expr.has(oo, -oo, zoo, nan).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top