Repository: scipy/scipy
File: scipy/special/_basic.py (Python)

Code before:
    else:
        n1 = n
    return _specfun.eulerb(n1)[:(n+1)]


def lqn(n, z):
    """Legendre functions of the second kind.

    Compute sequence of Legendre functions of the second kind, :math:`Q_n(z)` and
    derivatives for all degrees from :math:`0` to :math:`n` (inclusive).
    Returns two arrays of size :math:`(n+1,)` containing :math:`Q_n(z)` and
    :math:`Q_n'(z)`.

    Parameters
    ----------
    n : int
        Maximum degree of the Legendre functions.
    z : array_like, complex
        Real or complex input values.

    Returns
    -------
    Qn_z : ndarray, shape (n+1,) + shape(z)
        Values for all degrees 0..n
    Qn_d_z : ndarray, shape (n+1,) + shape(z)
        Derivatives for all degrees 0..n

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute :math:`Q_n(x)` and its derivatives on an interval.

    >>> import numpy as np
    >>> from scipy.special import lqn
    >>> import matplotlib.pyplot as plt

    >>> xs = np.linspace(-2, 2, 200)
    >>> n_max = 3
    >>> Qn, dQn = lqn(n_max, xs)

    Plot the Legendre functions of the second kind :math:`Q_n(x)`.

    >>> fig, ax = plt.subplots()
    >>> for n in range(n_max + 1):
    ...     ax.plot(xs, Qn[n], "-", label=rf"$n={n}$")
    >>> ax.set_xlabel(r"$x$")

Review comment (performance):
```suggestion
        Values for all degrees ``0...n``
    Qn_d_z : ndarray, shape (n+1,) + shape(z)
        Derivatives for all degrees ``0...n``
```

Code after:
    else:
        n1 = n
    return _specfun.eulerb(n1)[:(n+1)]


def lqn(n, z):
    """Legendre functions of the second kind.

    Compute sequence of Legendre functions of the second kind, ``Qn(z)`` and
    derivatives for all degrees from 0 to `n` (inclusive).
    Returns two arrays of size ``(n+1,) + z.shape`` containing ``Qn(z)`` and
    ``Qn'(z)``.

    Parameters
    ----------
    n : int
        Maximum degree of the Legendre functions.
    z : array_like, complex
        Real or complex input values.

    Returns
    -------
    Qn_z : ndarray, shape (n+1,) + shape(z)
        Values for all degrees ``0..n``
    Qn_d_z : ndarray, shape (n+1,) + shape(z)
        Derivatives for all degrees ``0..n``

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html

    Examples
    --------
    Compute :math:`Q_n(x)` and its derivatives on an interval.

    >>> import numpy as np
    >>> from scipy.special import lqn
    >>> import matplotlib.pyplot as plt

    >>> xs = np.linspace(-2, 2, 200)
    >>> n_max = 3
    >>> Qn, dQn = lqn(n_max, xs)

    Plot the Legendre functions of the second kind :math:`Q_n(x)`.

    >>> fig, ax = plt.subplots()
    >>> ax.plot(xs, Qn.T, "-")
    >>> ax.set_xlabel(r"$x$")
    >>> ax.set_ylabel(r"$Q_n(x)$")