SPHERICAL_JN
The spherical Bessel function of the first kind, j_n(z), is commonly used in radial wave equations in spherical coordinates.
It is related to the cylindrical Bessel function by:
j_n(z) = \sqrt{\frac{\pi}{2z}}\,J_{n+1/2}(z)
This function evaluates either j_n(z) or its derivative depending on the derivative flag.
Excel Usage
=SPHERICAL_JN(n, z, derivative)
n(int, required): Nonnegative integer order of the spherical Bessel function (dimensionless).z(float, required): Argument where the function is evaluated (dimensionless).derivative(bool, optional, default: false): Whether to return the derivative instead of the function value (true or false).
Returns (float): Value of the spherical Bessel function (or derivative) at order n and argument z.
Example 1: Zero order function value
Inputs:
| n | z | derivative |
|---|---|---|
| 0 | 1 | false |
Excel formula:
=SPHERICAL_JN(0, 1, FALSE)
Expected output:
0.841471
Example 2: First order function value
Inputs:
| n | z | derivative |
|---|---|---|
| 1 | 2 | false |
Excel formula:
=SPHERICAL_JN(1, 2, FALSE)
Expected output:
0.435398
Example 3: Second order derivative value
Inputs:
| n | z | derivative |
|---|---|---|
| 2 | 1.5 | true |
Excel formula:
=SPHERICAL_JN(2, 1.5, TRUE)
Expected output:
0.141474
Example 4: Third order at moderate argument
Inputs:
| n | z | derivative |
|---|---|---|
| 3 | 4 | false |
Excel formula:
=SPHERICAL_JN(3, 4, FALSE)
Expected output:
0.229244
Python Code
from scipy.special import spherical_jn as scipy_spherical_jn
def spherical_jn(n, z, derivative=False):
"""
Compute the spherical Bessel function of the first kind or its derivative.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.spherical_jn.html
This example function is provided as-is without any representation of accuracy.
Args:
n (int): Nonnegative integer order of the spherical Bessel function (dimensionless).
z (float): Argument where the function is evaluated (dimensionless).
derivative (bool, optional): Whether to return the derivative instead of the function value (true or false). Default is False.
Returns:
float: Value of the spherical Bessel function (or derivative) at order n and argument z.
"""
try:
n = int(n)
z = float(z)
derivative = bool(derivative)
if n < 0:
return "Error: n must be greater than or equal to 0"
return float(scipy_spherical_jn(n, z, derivative=derivative))
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Nonnegative integer order of the spherical Bessel function (dimensionless).
Argument where the function is evaluated (dimensionless).
Whether to return the derivative instead of the function value (true or false).