小编siv*_*ani的帖子

计算负实数值的 Gamma 函数(C++、Boost)

以下无限严重需要计算非整数、负数、实数的阶乘: 无限严肃:

(这是计算椭圆周长的一种方法,a和b是半长轴和半短轴,h定义为:
h = (ab)^2/(a+b)^2)

阶乘函数可以通过 Gamma 函数扩展到负值,该函数是为所有非负整数的实数定义的。

在编码严重时,我尝试了 boost::math::factorial 和 boost::math::tgamma ,它们给出的结果仅低至 -1 (不包括)-1.5 例如给出错误。

    #include <iostream>
    #include <boost/math/special_functions/factorials.hpp>

    int main()
    {
        double x;
        double f;
        double tg;

        x = -0.5;
        f = boost::math::factorial<double>(x);
        tg = boost::math::tgamma<double>(x);
        cout << "factorial of " << x << " = " << f << endl;
        cout << "tgamma of " << x << " = " << tg << endl << endl;

        x = -1.5;
        f = boost::math::factorial<double>(x);
        tg = boost::math::tgamma<double>(x);
        cout …
Run Code Online (Sandbox Code Playgroud)

c++ boost factorial gamma-function c++17

5
推荐指数
1
解决办法
700
查看次数

标签 统计

boost ×1

c++ ×1

c++17 ×1

factorial ×1

gamma-function ×1