Home > Src > Level_0 > pnleg.m

pnleg

PURPOSE ^

PNLEG Evaluates Legendre polynomial of degree n at x

SYNOPSIS ^

function [p] = pnleg (x, n)

DESCRIPTION ^

PNLEG      Evaluates Legendre polynomial of degree n at x

    [p]=pnleg(x,n) returns the evaluation of the Legendre
    polynomial of degree n at x, using the three
    term relation.
    (formula (2.3.3), pag. 75 CHQZ2)

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

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

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