Generates Legendre polynomials in MATLAB® polynomial form
Syntax
Pn = polyLegendre(n)
Description
n = polyLegendre(n), where n is a non-negative integer, returns the coefficients of the n-th degree Legendre polynomial in MATLAB® polynomial form.
Examples
Example 1 − An interesting (and useful) property of the Legendre polynomials
The Legendre polynomials have many interesting properties. For example, they are orthogonal on the interval
(with respect to a weight function of 1) as demonstrated in Example 2 of the polydefint function.
Another interesting (and extremely useful) property of the Legendre polynomials demonstrated in this example is that the roots
of the n-th degree Legendre polynomial,
, are the points of the n-point Gauss-Legendre quadrature rule, with the corresponding weights given by
For example, generating the second-degree Legendre polynomia
using the polyLegendre function
P2 = polyLegendre(2)
and then finding its roots using the roots functions
xi = roots(P2)’
yields the quadrature points of the well-known two-point Gauss-Legendre quadrature rule, i.e.,
. These nodes have corresponding weights of
, which can be obtained by first taking the derivative of P2 using the polyder function
dP2dx = polyder(P2)
and then evaluating the expression shown above for the weights to obtain
wi = 2./((1-xi.^2).*polyval(dP2dx,xi).^2)
The points and weights of this quadrature rule can be obtained directly from the quadGaussLegendre function (though computed in a more robust way in that function) and can be used to compute the definite integral of any polynomial of degree
exactly (said to be of degree 3) as demonstrated in Example 1 of the quadGaussLegendre function documentation in QuadTools.
Example 2 − Generating plots of the first few Legendre polynomials
A plot of the first few Legendre polynomials can be easily produced using the polyLegendre and polyplot functions in a loop, i.e.,
hold on; box on;
for i = 0:5
polyplot(polyLegendre(i),‘LineWidth’,1.5)
LegendText{i+1} = [‘P’,num2str(i)];
end
axis([-1 1 -1.1 1.1]);
title(‘Legendre Polynomials’);
legend(LegendText,‘Location’,‘best’);
This function is part of……..