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
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
andy1
. Ifn = 0
or 1, the routine fory0
ory1
is called directly.Array API Standard Support
yn
has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1
and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
⛔
JAX
⚠️ no JIT
⛔
Dask
✅
n/a
See Support for the array API standard for more information.
References
[1]Cephes Mathematical Functions Library, http://www.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 an 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()