Home > Src > Level_0 > pnleg_all.m

pnleg_all

PURPOSE ^

PNLEG_ALL Evaluates Legendre polynomials, from degree 0 to n

SYNOPSIS ^

function [p] = pnleg_all(x,n)

DESCRIPTION ^

PNLEG_ALL      Evaluates Legendre polynomials, from degree 0 to n

    [p]=pnleg_all(x,n) returns the evaluation of the Legendre
    polynomials of degree 0,1,...,N at x, using the three
    term relation (2.3.3), pag. 75 CHQZ2.

 Input: x = scalar or array
        n = degree of Legendre polynomial to be evalueted

 Output: p = 1-index (size(p)=size(x)) or 
             2-indexes (size(p)=[length(x),n+1])
             array containing the 
             evaluation of L_0(x), L_1(x), .... L_n(x)

 Reference: CHQZ2 = C. Canuto, M.Y. Hussaini, A. Quarteroni, T.A. Zang,
                    "Spectral Methods. Fundamentals in Single Domains"
                    Springer Verlag, Berlin Heidelberg New York, 2006.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [p] = pnleg_all(x,n) 
0002 %PNLEG_ALL      Evaluates Legendre polynomials, from degree 0 to n
0003 %
0004 %    [p]=pnleg_all(x,n) returns the evaluation of the Legendre
0005 %    polynomials of degree 0,1,...,N at x, using the three
0006 %    term relation (2.3.3), pag. 75 CHQZ2.
0007 %
0008 % Input: x = scalar or array
0009 %        n = degree of Legendre polynomial to be evalueted
0010 %
0011 % Output: p = 1-index (size(p)=size(x)) or
0012 %             2-indexes (size(p)=[length(x),n+1])
0013 %             array containing the
0014 %             evaluation of L_0(x), L_1(x), .... L_n(x)
0015 %
0016 % Reference: CHQZ2 = C. Canuto, M.Y. Hussaini, A. Quarteroni, T.A. Zang,
0017 %                    "Spectral Methods. Fundamentals in Single Domains"
0018 %                    Springer Verlag, Berlin Heidelberg New York, 2006.
0019 
0020 %   Written by Paola Gervasio
0021 %   $Date: 2007/04/01$
0022 
0023 
0024 nn=size(x);
0025 if nn==1
0026 if n==0
0027 p=1;
0028 elseif n==1
0029     p=[1,x];
0030 else
0031 p1=1;  p2=x;  p3=p2; p=[p1,p2];
0032 for k =1:n-1    
0033    p3=((2*k+1)*x*p2-k*p1)/(k+1); 
0034    p1=p2; 
0035    p2=p3; 
0036    p=[p,p3]; 
0037 end 
0038 end
0039 
0040 else
0041 if n==0
0042 p=ones(nn);
0043 elseif n==1
0044     p=[ones(nn),x];
0045 else
0046 p1=ones(nn);  p2=x;  p3=p2; p=[p1,p2];
0047 for k =1:n-1    
0048    p3=((2*k+1)*x.*p2-k*p1)/(k+1); 
0049    p1=p2; 
0050    p2=p3; 
0051    p=[p,p3]; 
0052 end 
0053 end
0054  
0055 end
0056 return

Generated on Fri 21-Sep-2007 10:07:00 by m2html © 2003