问题描述
我不知道是否有内置于像CMATH C ++标准库的一部分数学库统计功能。如果没有,你们可以推荐一个好统计库,将有一个累积正态分布函数?先谢谢了。
I was wondering if there were statistics functions built into math libraries that are part of the standard C++ libraries like cmath. If not, can you guys recommend a good stats library that would have a cumulative normal distribution function? Thanks in advance.
更具体地说,我期待使用/创建一个累积分布函数。
More specifically, I am looking to use/create a cumulative distribution function.
推荐答案
我想通了如何使用GSL,在谁在我面前回答人的建议去做,但后来发现非库解决方案(希望这可以帮助许多人在那里谁正在寻找像我):
I figured out how to do it using gsl, at the suggestion of the folks who answered before me, but then found a non-library solution (hopefully this helps many people out there who are looking for it like I was):
#ifndef Pi
#define Pi 3.141592653589793238462643
#endif
double cnd_manual(double x)
{
double L, K, w ;
/* constants */
double const a1 = 0.31938153, a2 = -0.356563782, a3 = 1.781477937;
double const a4 = -1.821255978, a5 = 1.330274429;
L = fabs(x);
K = 1.0 / (1.0 + 0.2316419 * L);
w = 1.0 - 1.0 / sqrt(2 * Pi) * exp(-L *L / 2) * (a1 * K + a2 * K *K + a3 * pow(K,3) + a4 * pow(K,4) + a5 * pow(K,5));
if (x < 0 ){
w= 1.0 - w;
}
return w;
}
这篇关于在C / C累积正态分布函数++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!