c++ - 如何将函数值更改为 C++ 中表(伽玛分布)中的值?
问题描述
我的任务是使用 C++ 编写一个程序,以使用 Gamma 分布计算概率。如果我已经找到函数值,如何将其更改为 Gamma 分布表中的值?我不知道公式。
例如 Fg(8;8),表中为 0.5470。表中的 Fg(4;8) 为 0.0511。
解决方案
从头开始用“纯”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
正如预期的那样
推荐阅读
- amazon-web-services - 扩展 websocket 广播服务器
- python - __init__() 得到了一个意外的关键字参数“py_func”
- python - AttributeError:“列表”对象没有属性“样本”
- javascript - 当我在 vue 方法中使用递归函数时,我不能通过 Array.prototyp.applly 更改它吗?
- python - Python使用lookahead/lookbehind替换整个单词
- json - 无法在 ubuntu 上永远启动 json-server
- keras - Keras CNN 模型总是返回 [0.5 0.5]
- python - 如何从 anaconda 卸载软件包
- java - 解码类型 [T] 的 JSON 流时出错:意外的令牌 (START_OBJECT),预期的 END_ARRAY:尝试解包
- laravel - Laravel - 身份验证用户返回 null