Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Module « scipy.special »

Fonction eval_legendre - module scipy.special

Signature de la fonction eval_legendre

Description

eval_legendre.__doc__

eval_legendre(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])

eval_legendre(n, x, out=None)

Evaluate Legendre polynomial at a point.

The Legendre polynomials can be defined via the Gauss
hypergeometric function :math:`{}_2F_1` as

.. math::

    P_n(x) = {}_2F_1(-n, n + 1; 1; (1 - x)/2).

When :math:`n` is an integer the result is a polynomial of degree
:math:`n`. See 22.5.49 in [AS]_ for details.

Parameters
----------
n : array_like
    Degree of the polynomial. If not an integer, the result is
    determined via the relation to the Gauss hypergeometric
    function.
x : array_like
    Points at which to evaluate the Legendre polynomial

Returns
-------
P : ndarray
    Values of the Legendre polynomial

See Also
--------
roots_legendre : roots and quadrature weights of Legendre
                 polynomials
legendre : Legendre polynomial object
hyp2f1 : Gauss hypergeometric function
numpy.polynomial.legendre.Legendre : Legendre series

References
----------
.. [AS] Milton Abramowitz and Irene A. Stegun, eds.
    Handbook of Mathematical Functions with Formulas,
    Graphs, and Mathematical Tables. New York: Dover, 1972.

Examples
--------
>>> from scipy.special import eval_legendre

Evaluate the zero-order Legendre polynomial at x = 0

>>> eval_legendre(0, 0)
1.0

Evaluate the first-order Legendre polynomial between -1 and 1

>>> X = np.linspace(-1, 1, 5)  # Domain of Legendre polynomials
>>> eval_legendre(1, X)
array([-1. , -0.5,  0. ,  0.5,  1. ])

Evaluate Legendre polynomials of order 0 through 4 at x = 0

>>> N = range(0, 5)
>>> eval_legendre(N, 0)
array([ 1.   ,  0.   , -0.5  ,  0.   ,  0.375])

Plot Legendre polynomials of order 0 through 4

>>> X = np.linspace(-1, 1)

>>> import matplotlib.pyplot as plt
>>> for n in range(0, 5):
...     y = eval_legendre(n, X)
...     plt.plot(X, y, label=r'$P_{}(x)$'.format(n))

>>> plt.title("Legendre Polynomials")
>>> plt.xlabel("x")
>>> plt.ylabel(r'$P_n(x)$')
>>> plt.legend(loc='lower right')
>>> plt.show()