Please enable java script to visit.
NOTEBOOK
HOMEPHP / MySQLJS / HTMLWXappPythonC++Blender其他
Hermite多项式,f(n,x) - NOTEBOOK
Hermite多项式,f(n,x)
C++
Posted on 2023-08-18
摘要 : 用递归的方法求Hermite多项式的值

用递归的方法求Hermite多项式的值,对给定的x和正整数n,求多项式的值。

❱ 输入描述

给定的n和x。

❱ 输出描述

多项式的值(保留两位小数)。

❱ 用例输入

1 2


❱ 用例输出

4.00


❱ 提示

提示:当n> 1 时 , 2 * x * h(n-1,x)-2*(n-1)*h(n-2,x)


#include <iostream>
#include <iomanip>
using namespace std;

double f(double n,double x){
if(n==0){
return 1;
}else if(n==1){
return 2*x;
}
return 2*x*f(n-1,x)-2*(n-1)*f(n-2,x);
}

int main(){
double n,x;
cin>>n>>x;
cout << fixed<<setprecision(2);
cout<<f(n,x);

return 0;
}