On Thu, Apr 3, 2014 at 5:11 AM, Moti <[email protected]> wrote: > Hi all, > > 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. > Specifically: > 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. >
If integrate returns an Integral, it just means it can't do it. You're hitting the limits of the integration algorithms implemented in SymPy. > > 3. Only using Integral(expression + parameters) gives the correct textual > expression (instead of integrate). > That's right. Integral is an unevaluated integral. > > 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. > This sounds like a bug. Can you report it at https://github.com/sympy/sympy/issues. For me, though, I get In [4]: Integral(exp(-0.5*(-x**2/2 + x**4/10)), (x, -oo, -3)).evalf() Out[4]: 0.0339709308483502 So please report the exact code you ran, so we can reproduce it. Aaron Meurer > > Any idea or maybe my usage is incorrect? > > Thanks!, > Moti. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/b11925fe-267c-4bea-8189-e4deccddecbb%40googlegroups.com<https://groups.google.com/d/msgid/sympy/b11925fe-267c-4bea-8189-e4deccddecbb%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6K6O_vobTdNjAS1H3FB9VEG%3DYWW381xfKQUjqcQ6-7eCA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
