legendreP
Legendre polynomials
Syntax
Description
returns the y = legendreP(n,x)nth degree Legendre
polynomial at x.
Examples
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 =
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 =
Find the Legendre polynomials of degrees 1 and 2 by setting n = [1 2].
syms x
y = legendreP([1 2],x)y =
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 =
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 =
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 =
t = taylor(y,x)
t =
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')

Use vpasolve to find the roots of the Legendre polynomial of degree 7.
syms x
roots = vpasolve(legendreP(7,x) == 0)roots =
Input Arguments
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
Legendre polynomial, returned as a number, vector, matrix, multidimensional array, or a symbolic number, vector, matrix, function, or multidimensional array.
More About
The Legendre polynomials are defined as
The Legendre polynomials satisfy the recursion formula
The Legendre polynomials are orthogonal on the interval [-1,1] with respect to the weight function w(x) = 1, where
The relation with Gegenbauer polynomials G(n,a,x) is
The relation with Jacobi polynomials P(n,a,b,x) is
Version History
Introduced in R2014b
See Also
chebyshevT | chebyshevU | gegenbauerC | hermiteH | hypergeom | jacobiP | laguerreL
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)