Main Content

legendreP

Legendre polynomials

Description

legendreP(n,x) returns the nth degree Legendre polynomial at x.

example

Examples

Find Legendre Polynomials for Numeric and Symbolic Inputs

Find the Legendre polynomial of degree 3 at 5.6.

legendreP(3,5.6)
ans =
  430.6400

Find the Legendre polynomial of degree 2 at x.

syms x
legendreP(2,x)
ans =
(3*x^2)/2 - 1/2

If you do not specify a numerical value for the degree n, the legendreP function cannot find the explicit form of the polynomial and returns the function call.

syms n
legendreP(n,x)
ans =
legendreP(n, x)

Find Legendre Polynomial with Vector and Matrix Inputs

Find the Legendre polynomials of degrees 1 and 2 by setting n = [1 2].

syms x
legendreP([1 2],x)
ans =
[ x, (3*x^2)/2 - 1/2]

legendreP acts element-wise on n to return a vector with two elements.

If multiple inputs are specified as a vector, matrix, or multidimensional array, the inputs must be the same size. Find the Legendre polynomials where input arguments n and x are matrices.

n = [2 3; 1 2];
xM = [x^2 11/7; -3.2 -x];
legendreP(n,xM)
ans =
[ (3*x^4)/2 - 1/2,        2519/343]
[           -16/5, (3*x^2)/2 - 1/2]

legendreP acts element-wise on n and x to return a matrix of the same size as n and x.

Differentiate and Find Limits of Legendre Polynomials

Use limit to find the limit of a Legendre polynomial of degree 3 as x tends to -∞.

syms x
expr = legendreP(4,x);
limit(expr,x,-Inf)
ans =
Inf

Use diff to find the third derivative of the Legendre polynomial of degree 5.

syms n
expr = legendreP(5,x);
diff(expr,x,3)
ans =
(945*x^2)/2 - 105/2

Find Taylor Series Expansion of Legendre Polynomial

Use taylor to find the Taylor series expansion of the Legendre polynomial of degree 2 at x = 0.

syms x
expr = legendreP(2,x);
taylor(expr,x)
ans =
(3*x^2)/2 - 1/2

Plot Legendre Polynomials

Plot Legendre polynomials of orders 1 through 4.

syms x y
fplot(legendreP(1:4, x))
axis([-1.5 1.5 -1 1])
grid on

ylabel('P_n(x)')
title('Legendre polynomials of degrees 1 through 4')
legend('1','2','3','4','Location','best')

Figure contains an axes object. The axes object with title Legendre polynomials of degrees 1 through 4, ylabel P indexOf n baseline (x) contains 4 objects of type functionline. These objects represent 1, 2, 3, 4.

Find Roots of Legendre Polynomial

Use vpasolve to find the roots of the Legendre polynomial of degree 7.

syms x
roots = vpasolve(legendreP(7,x) == 0)
roots =
 -0.94910791234275852452618968404785
 -0.74153118559939443986386477328079
 -0.40584515137739716690660641207696
                                   0
  0.40584515137739716690660641207696
  0.74153118559939443986386477328079
  0.94910791234275852452618968404785

Input Arguments

collapse all

Degree of polynomial, specified as a nonnegative number, vector, matrix, multidimensional array, or a symbolic number, vector, matrix, function, or multidimensional array. All elements of nonscalar inputs should be nonnegative integers or symbols.

Input, specified as a number, vector, matrix, multidimensional array, or a symbolic number, vector, matrix, function, or multidimensional array.

More About

collapse all

Legendre Polynomial

  • The Legendre polynomials are defined as

    P(n,x)=12nn!dndxn(x21)n.

  • The Legendre polynomials satisfy the recursion formula

    P(n,x)=2n1nxP(n1,x)n1nP(n2,x),whereP(0,x)=1P(1,x)=x.

  • The Legendre polynomials are orthogonal on the interval [-1,1] with respect to the weight function w(x) = 1, where

    x=1x=1P(n,x)P(m,x)dx={0if nm1n+1/2if n=m.

  • The relation with Gegenbauer polynomials G(n,a,x) is

    P(n,x)=G(n,12,x).

  • The relation with Jacobi polynomials P(n,a,b,x) is

    P(n,x)=P(n,0,0,x).

Version History

Introduced in R2014b