Bonnet’s recursion formula for Legendre polynomials is(adsbygoogle = window.adsbygoogle || []).push({});

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??Code (Text):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

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Error writing recursive function for Bonnet's recursion formula in C

**Physics Forums | Science Articles, Homework Help, Discussion**