scipy.special.yn#

scipy.special.yn(n, x, out=None) = <ufunc 'yn'>#

Bessel function of the second kind of integer order and real argument.

Parameters:
narray_like

Order (integer).

xarray_like

Argument (float).

outndarray, optional

Optional output array for the function results

Returns:
Yscalar or ndarray

Value of the Bessel function, \(Y_n(x)\).

See also

yv

For real order and real or complex argument.

y0

faster implementation of this function for order 0

y1

faster implementation of this function for order 1

Notes

Wrapper for the Cephes [1] routine yn.

The function is evaluated by forward recurrence on n, starting with values computed by the Cephes routines y0 and y1. If n = 0 or 1, the routine for y0 or y1 is called directly.

Array API Standard Support

yn has support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.

Library

CPU

GPU

NumPy

n/a

CuPy

n/a

PyTorch

JAX

Dask

n/a

For the NumPy backend, this function supports all NumPy ufunc keyword arguments. Other backends may support out, but none of the other ufunc kwargs. out is typically supported for CuPy and PyTorch, but not currently in cases where SciPy relies on a generic Array API implementation or, for PyTorch on CPU, falls back to the NumPy backend. out is never supported for JAX because JAX arrays are immutable. yn does not currently support out for the PyTorch backend.

See Support for the array API standard for more information.

References

[1]

Cephes Mathematical Functions Library, https://netlib.org/cephes/

Examples

Evaluate the function of order 0 at one point.

>>> from scipy.special import yn
>>> yn(0, 1.)
0.08825696421567697

Evaluate the function at one point for different orders.

>>> yn(0, 1.), yn(1, 1.), yn(2, 1.)
(0.08825696421567697, -0.7812128213002888, -1.6506826068162546)

The evaluation for different orders can be carried out in one call by providing a list or NumPy array as argument for the v parameter:

>>> yn([0, 1, 2], 1.)
array([ 0.08825696, -0.78121282, -1.65068261])

Evaluate the function at several points for order 0 by providing an array for z.

>>> import numpy as np
>>> points = np.array([0.5, 3., 8.])
>>> yn(0, points)
array([-0.44451873,  0.37685001,  0.22352149])

If z is an array, the order parameter v must be broadcastable to the correct shape if different orders shall be computed in one call. To calculate the orders 0 and 1 for a 1D array:

>>> orders = np.array([[0], [1]])
>>> orders.shape
(2, 1)
>>> yn(orders, points)
array([[-0.44451873,  0.37685001,  0.22352149],
       [-1.47147239,  0.32467442, -0.15806046]])

Plot the functions of order 0 to 3 from 0 to 10.

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> x = np.linspace(0., 10., 1000)
>>> for i in range(4):
...     ax.plot(x, yn(i, x), label=f'$Y_{i!r}$')
>>> ax.set_ylim(-3, 1)
>>> ax.legend()
>>> plt.show()
../../_images/scipy-special-yn-1.png