Skip to content Skip to sidebar Skip to footer

Dealing With Piecewise Equations Returned By Sympy Integrate

In sympy I have an integral which returns a Piecewise object, e.g. In [2]: from sympy.abc import x,y,z In [3]: test = exp(-x**2/z**2) In [4]: itest = integrate(test,(x,0,oo)) In

Solution 1:

In general, using .args is the correct way to access parts of an expression.

In this case, though, there is an option to integrate that will let you ignore convergence conditions

In [39]: integrate(test, (x, 0, oo), conds='none')
Out[39]:
  ___
╲╱ π ⋅z
───────
   2

Also, if you explicitly set the assumptions that you know on your variables, often the convergence conditions resolve themselves (it doesn't seem to happen in this case for any simple assumptions on z, though). For example, if you knew that z was real, use z = Symbol('z', real=True). Usually assuming that things are real, or even better positive, when you know it will help a lot in ensuring convergence.

Post a Comment for "Dealing With Piecewise Equations Returned By Sympy Integrate"