救命!!!用C++计算一个递推关系的函数

来源:百度知道 编辑:UC知道 时间:2024/06/28 16:15:37
计算一个递推关系的函数u(i)=x ^ i / i!(这里是i的阶乘) 其中x的数值为 f(x)=exp(x)

下面是我老师的例题 要按照这样的方法做 哎`捆扰我很久了 有谁能帮帮忙

u(i)= [(-1) ^ i ]/ [x^(2i+1) * (2i+1)]

f(x)= pi/2 - arctg(x)

#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>

ofstream file;
long double e = 0.00001, delta, u, prev_u = 0, x, summ = 0, pi = 3.1415, f_tan;
int i = 1;
bool till_end = 0;
char stop;

long double calc_u( long double x, int i )
{
return (-2*i+1)/((2*i+1)*x*x);
}

void print(char *t, int w, long double x) {
cout << t << setw(w) << x;
file << t << setw(w) << x;
}

void input(long double *x){
file.open("output.txt", ios::app);
while ( *x**x <1 ) {
cout << "BBEDUTE X. |X| >= 1\nX = ";
cin >> *x;
}
cout << endl << setpreci

u(i)=x ^ i / i!(这里是i的阶乘) 其中x的数值为 f(x)=exp(x)

int U(int i, int x)
{
if (i == 0)
return 1;
if (i == 1)
return x;
return U(i-1, x) * x / i;
}

...踩

可惜偶文件处理看不懂。。。