首页 > 解决方案 > 如何将函数值更改为 C++ 中表(伽玛分布)中的值?

问题描述

我的任务是使用 C++ 编写一个程序,以使用 Gamma 分布计算概率。如果我已经找到函数值,如何将其更改为 Gamma 分布表中的值?我不知道公式。

例如 Fg(8;8),表中为 0.5470。表中的 Fg(4;8) 为 0.0511。

标准伽玛累积表

标签: c++statisticsprobabilitygamma-distribution

解决方案


从头开始用“纯”C++ 编写这样的函数并不容易,因为 AFAIK C++ 标准库(通用数学函数数学特殊函数)不支持计算Gamma 分布累积函数所需的不完整 Gamma函数。

相反,我建议使用Boost 库的实现

// -*- compile-command: "g++ gamma.cpp; ./a.out"; -*-
//
#include <boost/math/distributions/gamma.hpp>
#include <iostream>

using namespace boost::math;

int main()
{
  gamma_distribution<> dist(8.,1);

  std::cout << "\n" << cdf(dist,8);
  std::cout << "\n" << cdf(dist,4);
}

印刷:

0.547039
0.0511336

正如预期的那样


推荐阅读