📄 d3r1.cpp
字号:
#include "iostream.h"
#include "math.h"
double func(double x)
{
return pow(x, 2) * (pow(x,2) - 2.0) * sin(x);
}
double fint(double x)
{
//integral of func
double aaa;
aaa = 4.0 * x * (pow(x,2) - 7.0) * sin(x);
return aaa - (pow(x , 4) - 14.0 * pow(x , 2) + 28.0) * cos(x);
}
void main()
{
//program d3r1
//driver for routine trapzd
int i;
const int nmax = 14;
double pio2 = 1.5707963;
double s,b,a = 0.0;
b = pio2;
cout<<endl;
cout<<"integral of func with 2^(n-1) points"<<endl;
cout<<"actual value of integral is: ";
cout<<(fint(b) - fint(a))<<endl;
cout<<endl;
cout<<" n approx.integral"<<endl;
cout.setf(ios::fixed|ios::right);
cout.precision(6);
for (i = 1; i<=nmax; i++)
{
trapzd(a, b, s, i);
cout.width(7);
cout<<i;
cout.width(16);
cout<<s<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -