First I must say that SymPy is a great tool, I came across it few weeks ago and...
Yesterday I was assigned a task to compute analytical expressions for some integrals and evaluate them.
1. exp(-0.5*(-x**2/2 + x**4/10)), x goes from -infinity to infinity, or from infinity to a finite value
2. exp(-0.5*(-x**2/2 + x**4/10)) * (-x**2/2 + x**4/10), same range
3. exp(-0.5*(-x**2/2 + x**4/10 - x/20)), same range
4. exp(-0.5*(-x**2/2 + x**4/10 - x/20)) * (-x**2/2 + x**4/10 - x/20), same range
Using mathematica, an analytic expresion for the first two can be found (using Integrate). The latter two are harder and can be obtained only numerically.
Using NIntegrate, the exact values can be obtained (for example in the range (-infinity, -3) or (3, infinity).
Matlab can also compute these numerically, using quadgk (Gauss-Kronrod method supporting infinites).
As for the issues I was facing:
1. First, the integrate function was failing because of the fraction values in the integrand (Coersion exception or so). It was fixed by installing the latest 0.7.5.
2. Using integrate, it only display the expression, even when specifying a range as tuple.
For example (assume x is a symbol):
integrate(exp(-0.5*(-x**2 / 2 + x**4 / 10)), (x, -float("inf"), -3))
The resulting expression is displayed as two integrals, each with a different range.
Changing to -oo doesn't matter much.
3. Only using Integral(expression + parameters) gives the correct textual expression (instead of integrate).
4. Evaluating the 1st and 3rd integrals with evalf() (of Integral) over the range (-infinity, -3) yields negative values which are clearly incorrect. Just as a testing example.
Any idea or maybe my usage is incorrect?
Thanks!,
Moti.