📄 d3r8.cpp
字号:
#include "iostream.h"
#include "math.h"
double func(double x)
{
return x * exp(-x);
}
void main()
{
//program d3r8
//driver for routine gauleg
int i,npoint = 10;
double x1 = 0.0;
double x2 = 1.0;
double x3 = 10.0;
double x[11], w[11];
gauleg(x1, x2, x, w, npoint);
cout<<endl;
cout<<" # x(i) w(i)"<<endl;
cout.setf(ios::fixed|ios::right);
cout.precision(6);
for (i = 1; i<=npoint; i++)
{
cout.width(2);
cout<<" "<<i;
cout.width(12);
cout<<x[i];
cout.width(12);
cout<<w[i]<<endl;
}
//demonstrate the use of gauleg for an integral
gauleg(x1, x3, x, w, npoint);
double xx = 0.0;
for (i = 1; i<=npoint; i++)
{
xx = xx + w[i] * func(x[i]);
}
cout<<endl;
cout<<"integral from gauleg: "<<xx<<endl;
cout<<"actual value: ";
cout<<(1.0 - (1.0 + x3) * exp(-x3))<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -