Contenuto principale

legendreP

Legendre polynomials

Description

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

example

Examples

collapse all

Find the Legendre polynomial of degree 3 at 5.6.

y = legendreP(3,5.6)
y = 
430.6400

Find the Legendre polynomial of degree 2 at x.

syms x
y = legendreP(2,x)
y = 

3x22-12

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
y = legendreP(n,x)
y = legendreP(n,x)

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

syms x
y = legendreP([1 2],x)
y = 

(x3x22-12)

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];
yM = legendreP(n,xM)
yM = 

(3x42-122519343-1653x22-12)

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

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

syms x
P3 = legendreP(3,x);
P3 = limit(P3,x,-Inf)
P3 = -

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

P5 = legendreP(5,x);
D3P5 = diff(P5,x,3)
D3P5 = 

945x22-1052

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

syms x
y = legendreP(2,x)
y = 

3x22-12

t = taylor(y,x)
t = 

3x22-12

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.

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.4058451513773971669066064120769600.405845151377397166906606412076960.741531185599394439863864773280790.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.

Output Arguments

collapse all

Legendre polynomial, returned as a number, vector, matrix, multidimensional array, or a symbolic number, vector, matrix, function, or multidimensional array.

More About

collapse all

Version History

Introduced in R2014b