qsimp.cpp
来自「这是C++数值算法(第二版)的源代码,其中包含了目前一些比较常用的数值计算的算法」· C++ 代码 · 共 24 行
CPP
24 行
#include <cmath>
#include "nr.h"
using namespace std;
DP NR::qsimp(DP func(const DP), const DP a, const DP b)
{
const int JMAX=20;
const DP EPS=1.0e-10;
int j;
DP s,st,ost=0.0,os=0.0;
for (j=0;j<JMAX;j++) {
st=trapzd(func,a,b,j+1);
s=(4.0*st-ost)/3.0;
if (j > 5)
if (fabs(s-os) < EPS*fabs(os) ||
(s == 0.0 && os == 0.0)) return s;
os=s;
ost=st;
}
nrerror("Too many steps in routine qsimp");
return 0.0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?