用遞歸方法求n階勒讓德多項式的值


/*
 Date: 07/03/19 15:40
 Description: 用遞歸法求n階勒讓德多項式的值
           { 1     n=0
      Pn(x)=  { x     n=1
           { ((2n-1).x-Pn-1(x)-(n-1).Pn-2(x)/n   n>=1
*/

#include<stdio.h>

float Legendre(int x,int n);

int main(void)

{

   int x,n;

   float value;

   printf("Enter the order of the polynomials:\n");

     scanf("%d %d",&n,&x);

   printf("n=%d,x=%d\n\n",n,x);

     value=Legendre(x,n);

   printf("P%d(%d)=%6.3f\n",n,x,value);

   return 0;

 }

float Legendre(int x,int n)

 {

   float value;

    if(n==0)

       value=1;

    else if(n==1)

       value=x;

    else

       value=((2*n-1)*x-Legendre(x,n-1)-(n-1)*Legendre(x,n-2))/n;

    return value;

 }

 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM