Skip to content

Commit

Permalink
Trac #15019: Fixing differentiation
Browse files Browse the repository at this point in the history
  • Loading branch information
eviatarbach committed Aug 7, 2013
1 parent ddf5d57 commit 4b3426e
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions src/sage/functions/bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def _evalf_(self, n, x, parent=None):
import mpmath
return mpmath_utils.call(mpmath.besselj, n, x, parent=parent)

def _derivative_(self, n, x, diff_param=None):
def _derivative_(self, n, x, diff_param):
"""
Return the derivative of the Bessel J function.
Expand All @@ -360,8 +360,17 @@ def _derivative_(self, n, x, diff_param=None):
sage: f(z) = bessel_J(10, z)
sage: derivative(f, z)
z |--> -1/2*bessel_J(11, z) + 1/2*bessel_J(9, z)
sage: nu = var('nu')
sage: bessel_J(nu, z).diff(nu)
Traceback (most recent call last):
...
NotImplementedError: derivative with respect to order
"""
return (bessel_J(n - 1, x) - bessel_J(n + 1, x)) / Integer(2)
if diff_param == 1:
return (bessel_J(n - 1, x) - bessel_J(n + 1, x)) / Integer(2)
else:
raise NotImplementedError('derivative with respect to order')

def _print_latex_(self, n, z):
"""
Expand Down Expand Up @@ -511,7 +520,7 @@ def _evalf_(self, n, x, parent=None):
import mpmath
return mpmath_utils.call(mpmath.bessely, n, x, parent=parent)

def _derivative_(self, n, x, diff_param=None):
def _derivative_(self, n, x, diff_param):
"""
Return the derivative of the Bessel Y function.
Expand All @@ -520,8 +529,16 @@ def _derivative_(self, n, x, diff_param=None):
sage: f(x) = bessel_Y(10, x)
sage: derivative(f, x)
x |--> -1/2*bessel_Y(11, x) + 1/2*bessel_Y(9, x)
sage: nu = var('nu')
sage: bessel_Y(nu, x).diff(nu)
Traceback (most recent call last):
...
NotImplementedError: derivative with respect to order
"""
return (bessel_Y(n - 1, x) - bessel_Y(n + 1, x)) / Integer(2)
if diff_param == 1:
return (bessel_Y(n - 1, x) - bessel_Y(n + 1, x)) / Integer(2)
else:
raise NotImplementedError('derivative with respect to order')

def _print_latex_(self, n, z):
"""
Expand Down Expand Up @@ -683,7 +700,7 @@ def _evalf_(self, n, x, parent=None):
import mpmath
return mpmath_utils.call(mpmath.besseli, n, x, parent=parent)

def _derivative_(self, n, x, diff_param=None):
def _derivative_(self, n, x, diff_param):
"""
Return the derivative of the Bessel I function `I_n(x)` with respect
to `x`.
Expand All @@ -693,8 +710,16 @@ def _derivative_(self, n, x, diff_param=None):
sage: f(z) = bessel_I(10, x)
sage: derivative(f, x)
z |--> 1/2*bessel_I(11, x) + 1/2*bessel_I(9, x)
sage: nu = var('nu')
sage: bessel_I(nu, x).diff(nu)
Traceback (most recent call last):
...
NotImplementedError: derivative with respect to order
"""
return (bessel_I(n - 1, x) + bessel_I(n + 1, x)) / Integer(2)
if diff_param == 1:
return (bessel_I(n - 1, x) + bessel_I(n + 1, x)) / Integer(2)
else:
raise NotImplementedError('derivative with respect to order')

def _print_latex_(self, n, z):
"""
Expand Down Expand Up @@ -869,7 +894,7 @@ def _evalf_(self, n, x, parent=None):
import mpmath
return mpmath_utils.call(mpmath.besselk, n, x, parent=parent)

def _derivative_(self, n, x, diff_param=None):
def _derivative_(self, n, x, diff_param):
"""
Return the derivative of the Bessel K function.
Expand All @@ -878,8 +903,16 @@ def _derivative_(self, n, x, diff_param=None):
sage: f(x) = bessel_K(10, x)
sage: derivative(f, x)
x |--> 1/2*bessel_K(11, x) + 1/2*bessel_K(9, x)
sage: nu = var('nu')
sage: bessel_K(nu, x).diff(nu)
Traceback (most recent call last):
...
NotImplementedError: derivative with respect to order
"""
return (bessel_K(n - 1, x) + bessel_K(n + 1, x)) / Integer(2)
if diff_param == 1:
return (bessel_K(n - 1, x) + bessel_K(n + 1, x)) / Integer(2)
else:
raise NotImplementedError('derivative with respect to order')

def _print_latex_(self, n, z):
"""
Expand Down

0 comments on commit 4b3426e

Please sign in to comment.