用递归方法求n阶勒让德多项式的值 C++源代码

2016-06-21 21:40:14  分类: c++程序设计第三版谭浩强课后答案  参与:

 用递归方法求n阶勒让德多项式的值,递归公式为:
             {    1     (n=0)
  pn(x)={    x     (n=1)
             {   ((2n-1)*x - pn-1(x)  -(n-1)*pn-2(x))/n     (n>=1)

以下是此题的【c++源代码】,需要【c源代码】请点击进入

#include <iostream>
using namespace std;
int main()
 {int x,n;
  float p(int,int);
  cout<<"input n & x:";
  cin>>n>>x;
  cout<<"n="<<n<<",x="<<x<<endl;;
  cout<<"P"<<n<<"(x)="<<p(n,x)<<endl;
  return 0;
 }

float p(int n,int x)
 {if (n==0)
    return(1);
  else if (n==1)
    return(x);
  else
    return(((2*n-1)*x*p((n-1),x)-(n-1)*p((n-2),x))/n);
 }
 

来源:c++程序设计第三版谭浩强课后答案

本文链接:http://www.wb98.com/cjia/post/cjia_4.8.html


本站文章搜索:

<< 上一篇下一篇 >>

搜索

Tags列表

赞助商链接