SPHERICAL_KN

The modified spherical Bessel function of the second kind, k_n(z), is a decaying spherical solution used in screened or evanescent radial fields.

It is related to the modified cylindrical Bessel function by:

k_n(z) = \sqrt{\frac{\pi}{2z}}\,K_{n+1/2}(z)

This function evaluates either k_n(z) or its derivative depending on the derivative flag.

Excel Usage

=SPHERICAL_KN(n, z, derivative)
  • n (int, required): Nonnegative integer order of the modified spherical Bessel function (dimensionless).
  • z (float, required): Positive 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 modified spherical Bessel function of the second kind (or derivative).

Example 1: Zero order function value

Inputs:

n z derivative
0 1 false

Excel formula:

=SPHERICAL_KN(0, 1, FALSE)

Expected output:

0.577864

Example 2: First order function value

Inputs:

n z derivative
1 2 false

Excel formula:

=SPHERICAL_KN(1, 2, FALSE)

Expected output:

0.159438

Example 3: Second order derivative value

Inputs:

n z derivative
2 1.5 true

Excel formula:

=SPHERICAL_KN(2, 1.5, TRUE)

Expected output:

-2.4145

Example 4: Third order at moderate argument

Inputs:

n z derivative
3 2.5 false

Excel formula:

=SPHERICAL_KN(3, 2.5, FALSE)

Expected output:

0.348651

Python Code

from scipy.special import spherical_kn as scipy_spherical_kn

def spherical_kn(n, z, derivative=False):
    """
    Compute the modified spherical Bessel function of the second kind or its derivative.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.spherical_kn.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        n (int): Nonnegative integer order of the modified spherical Bessel function (dimensionless).
        z (float): Positive 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 modified spherical Bessel function of the second kind (or derivative).
    """
    try:
        n = int(n)
        z = float(z)
        derivative = bool(derivative)
        if n < 0:
            return "Error: n must be greater than or equal to 0"
        if z <= 0:
            return "Error: z must be greater than 0 for real-valued output"
        return float(scipy_spherical_kn(n, z, derivative=derivative))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Nonnegative integer order of the modified spherical Bessel function (dimensionless).
Positive argument where the function is evaluated (dimensionless).
Whether to return the derivative instead of the function value (true or false).