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:
- n : array_like
Order (integer).
Bessel function of the second kind of integer order and real argument.
Order (integer).
Argument (float).
Optional output array for the function results
Value of the Bessel function, .
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 experimental support for Python Array API Standard compatible
backends in addition to NumPy. Please consider testing these features
by setting an environment variable SCIPY_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 | ✅ | ⛔ |
Dask | ✅ | n/a |
See Support for the array API standard for more information.
Cephes Mathematical Functions Library, https://netlib.org/cephes/
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