gpt4 book ai didi

c++ - 如何将函数值更改为 C++ 中表( Gamma 分布)中的值?

转载 作者:行者123 更新时间:2023-11-30 04:43:15 28 4
gpt4 key购买 nike

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

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

Standard Gamma Cumulative Table

最佳答案

从头开始用“纯”C++ 编写这样的函数并不容易,因为 AFAIK C++ 标准库(Common mathematical functionsMathematical special functions)不支持 incomplete Gamma function这是计算 Gamma distribution cumulative function 所必需的.

相反,我建议使用 Boost library's implementation

// -*- 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

如预期的那样

关于c++ - 如何将函数值更改为 C++ 中表( Gamma 分布)中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58379407/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com