?? 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 + -