legendre0 edit page

Evaluate all Legendre polynomials up to degree N in x and returns a matrix of the function values 1st dimension -> degree 2nd dimension -> x Use the recurrence formula (n+1)*P_{n+1} = (2n+1)*x*P_n - n*P_{n-1}

Syntax

l = legendre0(N,x)

Input

N degree
x input nodes

Output

l function evaluations

Example

x = -1:0.2:1
l = legendre0(10,x)
x =
  Columns 1 through 7
   -1.0000   -0.8000   -0.6000   -0.4000   -0.2000         0    0.2000
  Columns 8 through 11
    0.4000    0.6000    0.8000    1.0000
l =
  Columns 1 through 7
    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000
   -1.0000   -0.8000   -0.6000   -0.4000   -0.2000         0    0.2000
    1.0000    0.4600    0.0400   -0.2600   -0.4400   -0.5000   -0.4400
   -1.0000   -0.0800    0.3600    0.4400    0.2800         0   -0.2800
    1.0000   -0.2330   -0.4080   -0.1130    0.2320    0.3750    0.2320
   -1.0000    0.3995    0.1526   -0.2706   -0.3075         0    0.3075
    1.0000   -0.3918    0.1721    0.2926   -0.0806   -0.3125   -0.0806
   -1.0000    0.2397   -0.3226    0.0146    0.2935         0   -0.2935
    1.0000   -0.0167    0.2123   -0.2670   -0.0396    0.2734   -0.0396
   -1.0000   -0.1879    0.0461    0.1888   -0.2460         0    0.2460
    1.0000    0.3005   -0.2437    0.0968    0.1291   -0.2461    0.1291
  Columns 8 through 11
    1.0000    1.0000    1.0000    1.0000
    0.4000    0.6000    0.8000    1.0000
   -0.2600    0.0400    0.4600    1.0000
   -0.4400   -0.3600    0.0800    1.0000
   -0.1130   -0.4080   -0.2330    1.0000
    0.2706   -0.1526   -0.3995    1.0000
    0.2926    0.1721   -0.3918    1.0000
   -0.0146    0.3226   -0.2397    1.0000
   -0.2670    0.2123   -0.0167    1.0000
   -0.1888   -0.0461    0.1879    1.0000
    0.0968   -0.2437    0.3005    1.0000

compare with MATLABs legendre, whose first row is the Legendre polynomial of degree k

err = 0;
for k = 0:10
P = legendre(k,x);
err = max(err,max(abs(P(1,:) - l(k+1,:))));
end
err
err =
   3.8858e-16

Citing this page. This page is part of the documentation of MTEX, a free and open source MATLAB toolbox for analyzing and modeling crystallographic textures. It was written by The MTEX Developers and is published at https://mtex-toolbox.github.io/legendre0.html. If you use MTEX, or reuse text or figures from this page, in your research, please cite

F. Bachmann, R. Hielscher, H. Schaeben: Texture Analysis with MTEX - Free and Open Source Software Toolbox, Solid State Phenomena 160 (2010), 63-68. 10.4028/www.scientific.net/SSP.160.63

BibTeX
@article{bachmann2010mtex,
  author  = {F. Bachmann and R. Hielscher and H. Schaeben},
  title   = {Texture Analysis with MTEX - Free and Open Source Software Toolbox},
  journal = {Solid State Phenomena},
  volume  = {160},
  pages   = {63-68},
  year    = {2010},
  doi     = {10.4028/www.scientific.net/SSP.160.63},
  url     = {https://doi.org/10.4028/www.scientific.net/SSP.160.63}
}

Other papers describing specific MTEX methods are listed under Publications — please cite the one that best fits your application. The MTEX source code is licensed under the GNU General Public License v2.0; the text and figures of this documentation are licensed under CC BY 4.0, which permits reuse — including by automated systems — provided The MTEX Developers and this page are credited.