Search code examples
pythonscipybessel-functions

Zeroth-order Bessel function Python


Apologies for the simplicity of this question.

I would like to implement an equation in Python. In this equation, K_0 is the zeroth-order modifed Bessel function.

What is the best way of implementing K_0 in Python?


Solution

  • No need to implement it; it's included. See the docs for the scipy.special module, in particular the optimized common ones here:

    >>> import scipy.special
    >>> print scipy.special.k0.__doc__
    k0(x[, out])
    
    y=k0(x) returns the modified Bessel function of the second kind (sometimes called the third kind) of
    order 0 at x.
    >>> scipy.special.k0(1)
    0.42102443824070823
    

    or more generally:

    >>> print scipy.special.kn.__doc__
    kn(x1, x2[, out])
    
    y=kn(n,x) returns the modified Bessel function of the second kind (sometimes called the third kind) for
    integer order n at x.
    >>> scipy.special.kn(0, 1)
    0.42102443824070834