Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
17678: special values of Bessel functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Jan 28, 2015
1 parent a70d682 commit 191ca28
Showing 1 changed file with 84 additions and 17 deletions.
101 changes: 84 additions & 17 deletions src/sage/functions/bessel.py
Expand Up @@ -97,7 +97,7 @@
sage: bessel_J(0, x)
bessel_J(0, x)
sage: bessel_J(0, 0)
bessel_J(0, 0)
1
sage: bessel_J(0, x).diff(x)
-1/2*bessel_J(1, x) + 1/2*bessel_J(-1, x)
Expand Down Expand Up @@ -194,11 +194,12 @@

# remove after deprecation period
from sage.calculus.calculus import maxima
from sage.functions.other import real, imag
from sage.functions.trig import sin, cos
from sage.functions.other import real, imag, sqrt
from sage.misc.sage_eval import sage_eval
from sage.rings.real_mpfr import RealField
from sage.plot.plot import plot
from sage.rings.all import ZZ
from sage.rings.all import ZZ, QQ


class Function_Bessel_J(BuiltinFunction):
Expand Down Expand Up @@ -303,6 +304,34 @@ def __init__(self):
maxima='bessel_j',
sympy='besselj'))

def _eval_(self, n, x):
"""
EXAMPLES::
sage: bessel_J(0, 0)
1
sage: bessel_J(5/2, 0)
0
sage: bessel_J(-5/2, 0)
+Infinity
sage: bessel_J(1/2, x)
sqrt(2)*sqrt(1/(pi*x))*sin(x)
sage: bessel_J(-1/2, x)
sqrt(2)*sqrt(1/(pi*x))*cos(x)
"""
from sage.rings.infinity import infinity
if x == 0:
if n == 0:
return ZZ(1)
elif n > 0 or n in ZZ:
return ZZ(0)
else:
return infinity
if n == QQ(1)/2:
return sqrt(2/pi/x) * sin(x)
elif n == QQ(-1)/2:
return sqrt(2/pi/x) * cos(x)

def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
Expand Down Expand Up @@ -475,6 +504,25 @@ def __init__(self):
maxima='bessel_y',
sympy='bessely'))

def _eval_(self, n, x):
"""
EXAMPLES::
sage: bessel_Y(1, 0)
-Infinity
sage: bessel_Y(1/2, x)
-sqrt(2)*sqrt(1/(pi*x))*cos(x)
sage: bessel_Y(-1/2, x)
sqrt(2)*sqrt(1/(pi*x))*sin(x)
"""
from sage.rings.infinity import infinity
if x == 0 and n >= 0:
return -infinity
if n == QQ(1)/2:
return -sqrt(2/pi/x) * cos(x)
elif n == QQ(-1)/2:
return sqrt(2/pi/x) * sin(x)

def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
Expand Down Expand Up @@ -645,25 +693,40 @@ def _eval_(self, n, x):
EXAMPLES::
sage: y=var('y')
sage: bessel_I(y,x)
sage: bessel_I(y, x)
bessel_I(y, x)
sage: bessel_I(0.0, 1.0)
1.26606587775201
sage: bessel_I(0, 0)
1
sage: bessel_I(7/2, 0)
0
sage: bessel_I(-7/2, 0)
+Infinity
sage: bessel_I(1/2, 1)
sqrt(2)*sinh(1)/sqrt(pi)
sage: bessel_I(-1/2, pi)
sqrt(2)*cosh(pi)/pi
"""
from sage.rings.infinity import infinity
# special identities
if n == Integer(1) / Integer(2):
if x == 0:
if n == 0:
return ZZ(1)
elif n > 0 or n in ZZ:
return ZZ(0)
else:
return infinity
if n == QQ(1)/2:
return sqrt(2 / (pi * x)) * sinh(x)
elif n == -Integer(1) / Integer(2):
elif n == -QQ(1)/2:
return sqrt(2 / (pi * x)) * cosh(x)


def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
sage: bessel_I(0.0, 1.0)
1.26606587775201
sage: bessel_I(1,3).n(digits=20)
3.9533702174026093965
"""
Expand Down Expand Up @@ -739,9 +802,9 @@ class Function_Bessel_K(BuiltinFunction):
-1/2*bessel_K(3, x) - 1/2*bessel_K(1, x)
sage: bessel_K(1/2, x)
bessel_K(1/2, x)
sqrt(1/2)*sqrt(pi)*e^(-x)/sqrt(x)
sage: bessel_K(1/2, -1)
bessel_K(1/2, -1)
-I*sqrt(1/2)*sqrt(pi)*e
sage: bessel_K(1/2, 1)
sqrt(1/2)*sqrt(pi)*e^(-1)
Expand Down Expand Up @@ -817,23 +880,27 @@ def _eval_(self, n, x):
"""
EXAMPLES::
sage: bessel_K(1,0)
bessel_K(1, 0)
sage: bessel_K(1.0, 0.0)
+infinity
sage: bessel_K(-1, 1).n(128)
0.60190723019723457473754000153561733926
sage: bessel_K(1, 0)
+Infinity
sage: bessel_K(1/2, x)
sqrt(1/2)*sqrt(pi)*e^(-x)/sqrt(x)
"""
from sage.rings.infinity import infinity
# special identity
if n == Integer(1) / Integer(2) and x > 0:
if x == 0:
return infinity
if n == QQ(1)/2 or n == -QQ(1)/2 and x > 0:
return sqrt(pi / 2) * exp(-x) * x ** (-Integer(1) / Integer(2))


def _evalf_(self, n, x, parent=None, algorithm=None):
"""
EXAMPLES::
sage: bessel_K(0.0, 1.0)
0.421024438240708
sage: bessel_K(-1, 1).n(128)
0.60190723019723457473754000153561733926
sage: bessel_K(0, RealField(128)(1))
0.42102443824070833333562737921260903614
"""
Expand Down

0 comments on commit 191ca28

Please sign in to comment.