For 9 terms, mpmath.fac gives me 2.14373016357422 and sympy.factorial gives
me 1.88592361267614 (also mpmath.fac is much slower; SymPy in general
handles exact integers better than floats). Given the two, I'm inclined to
believe the SymPy version, since it deals with exact numbers, so there is
no chance for numerical instability until the end (and the intermediate
T_rfe has a lot of very small floats, so I think there is indeed a lot of
instability going on).

Some other notes on your code:

- Si is already implemented in SymPy. You can use Si(x).series(x, 0,
n).removeO() to get the series of Si up to x**n.
- Just use sympy.pi. It will know how to evaluate itself in the end.
- Use T_rfe.evalf(subs={N: 8}) at the end to evaluate the expression, or if
you want to use numpy, use lambdify. If you are worried about numerical
instability you can increase the precision (at the end) by passing an
argument to evalf(), like T_rfe.evalf(100, subs={N: 8}).

Aaron Meurer


On Wed, Jul 15, 2015 at 3:01 PM, <[email protected]> wrote:

> Hello,
>
> I need to integrate sinc(x) twice. To do this I have used the series
> expansion for sinc, which is a summation that includes a factorial term. I
> have attached my current code.
>
> If I use the factorial function in sympy, this sequence does not appear to
> converge. If I use mpmath.factorial, it appears to converge after 8 terms
> (the number of terms can be changed on line 14). However this "convergence"
> is very abrupt - there is a large relative change between 7 & 8 terms, and
> then absolutely no change for 9 terms. Hence I am concerned I am hitting
> some precision limit and not actual convergence.
>
> I would be very grateful if someone can sanity check my code. I am
> unfamiliar with the mpmath module, I only stumbled across the
> mpmath.factorial function through Google.
>
> Thanks in advance,
> Toby Wood
>
>  --
> 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/05839053-a5ed-4c34-b02b-fe49773fa5c6%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/05839053-a5ed-4c34-b02b-fe49773fa5c6%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%3D6KLpUbsL4PPD7AU7DBU5hk-R7hmG6uqWRohzwQT%2Bkog7w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to