On Mon, Oct 27, 2008 at 2:37 PM, Neal Becker <[EMAIL PROTECTED]> wrote:
>
> On Friday 24 October 2008, Fredrik Johansson wrote:
>> On Fri, Oct 24, 2008 at 3:53 PM, Neal Becker <[EMAIL PROTECTED]> wrote:
>> > I'm a noob to sympy.  I need something to replace ive from cephes.  iv is
>> > the modified bessel function of order v, while ive is the exponentially
>> > scaled version: exp(-|x|) I(v,x)
>> >
>> > Any suggestions?
>>
>> Replace how? What features do you need?
>>
>> Fredrik
>>
> Sorry, I'll try to describe better.
>
> I have a calculation of probability which involves things like factorial,
> exponential, and also Ive.  It was working fine using scipy.  Now I need to
> extend it to larger parameter values, and the calculation blows up (involves
> things like 512!).  I thought, why not try using sympy?  It has extended
> precision.  I noticed that sympy has some bessel functions, but not the ones I
> need.

Well, mpmath handles big floating-point factorials without trouble:

>>> from mpmath import *
>>> fac(512)
mpf('3.4772897931326054e+1166')

Mpmath doesn't have the Bessel I function, but it's not too hard to
write a basic implementation:

from mpmath import *
from mpmath.functions import funcwrapper

@funcwrapper
def ive(v,z):
    s = hyp1f1(v+0.5, 2*v+1, 2*z)
    c = z**v / (2**v * exp(z) * gamma(v+1))
    return exp(-abs(z)) * s*c

>>> mp.dps = 50
>>> print ive(3, 0.5)
0.0016043415075654608433293663669854375123123266820256
>>>
>>> from scipy.special import ive
>>> ive(3, 0.5)
0.0016043415075654604

(However, this implementation will not be fast for very large z. You'd
have to use an asymptotic series for that.)

Fredrik

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to