- #1
PrakashPhy
- 35
- 0
Bonnet’s recursion formula for Legendre polynomials is
P(n,x)=1 for n=0
P(n,x)=x for n=1 and
P(n,x)= (2n-1)/n*x*P(n-1,x)-(n-1)/n*P(n-2,x)
I tried to write recursive function in C to calculate the value of polynomial for a given n and x
But this doesn't give the correct result. What's wrong with the function??
Thanks in advance
P(n,x)=1 for n=0
P(n,x)=x for n=1 and
P(n,x)= (2n-1)/n*x*P(n-1,x)-(n-1)/n*P(n-2,x)
I tried to write recursive function in C to calculate the value of polynomial for a given n and x
Code:
float legpol(int n, float x)
{
if(n==0)
return 1;
else if(n==1)
return x;
else
return(2*n-1)/n*x*legpol(n-1,x)-(n-1)/n*legpol(n-2,x);
}
Thanks in advance