问题描述
我一直试图在我的 C++ 项目中编写一个函数来计算正态逆累积分布函数,就像 Matlab (https://www.mathworks.com/help/stats/norminv.html?s_tid=doc_ta) 中的 norminv 函数一样。我也想用自定义均值和标准差来做。
这是我的功能:
double norminv(double p,double mean,double sigma)
{
double x;
double buffer;
x = mean;
for (int i = 0; i <= 500; i++) {
//I calculate the normal cumulative distribution of the mean
buffer = (0.5) * (2.0 - erfc((x - mean) / (sigma * sqrt(2))));
//If the needed number is smaller than the mean,then I reduce x and repeat
if (buffer > p)
x -= x / 10;
//If the needed number is bigger than the mean,then I increase x and repeat
else if (buffer < p)
x += x / 10;
//If it equals buffer,then x is the mean
else
x = mean;
return x;
}
这是我的代码。它不是很准确,有时只是错误,但我不确定如何更有效地计算正态累积分布。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)