Home > bioelectromagnetism > LegendreP.m

LegendreP

PURPOSE ^

function p=LegendreP(nmax,x)

SYNOPSIS ^

function p=LegendreP(nmax,x)

DESCRIPTION ^

 function p=LegendreP(nmax,x)
 Computes all Legendre polynomials from n=0 to n=nmax,
 arranges them in an array from n=1 to nmax+1.
 Uses the recursion relation in Numerical Recipes.
 T Ferree at EGI
 revised 1/19/00

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function p=LegendreP(nmax,x)
0002 
0003 % function p=LegendreP(nmax,x)
0004 % Computes all Legendre polynomials from n=0 to n=nmax,
0005 % arranges them in an array from n=1 to nmax+1.
0006 % Uses the recursion relation in Numerical Recipes.
0007 % T Ferree at EGI
0008 % revised 1/19/00
0009 
0010 p=zeros(nmax+1,1);
0011 
0012 if nmax>=0,
0013     p0=1.0;
0014     p(1)=p0;
0015 end
0016 
0017 if nmax>=1,
0018     p1=x;
0019     p(2)=p1;
0020 end
0021 
0022 if nmax>=2,
0023     for j=2:nmax,
0024         %         c1=(2.0*j-1.0)/(1.0*j);
0025         %         c2=(1.0*j-1.0)/(1.0*j);
0026         %         p(j+1)=c1*x*p(j-1+1)-c2*p(j-2+1);
0027         c1=(2.0*j-1.0)/j;
0028         c2=    (j-1.0)/j;
0029         p(j+1) = c1*x*p(j) - c2*p(j-1);
0030     end
0031 end
0032 
0033 return;

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003