5

次の無限深刻では、非整数、負、実数の階乗の計算が必要です。 無限に深刻:

(これは楕円の円周を計算する方法です。a と b は長半径と短半径で、h は次のように定義されます:
h = (ab)^2/(a+b)^2)

階乗関数は、負の整数ではないすべての実数に対して定義されているガンマ関数を介して負の値に拡張できます。

深刻なコーディング中に、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 << "factorial of " << x << " = " << f << endl;
        cout << "tgamma of " << x << " = " << tg << endl << endl;
    
        return 0;
    }

出力:

-0.5 の階乗 = 1 -0.5
の tgamma = -3.54491
'boost::exception_detail::clone_implboost::exception_detail::error_info_injector<std::domain_error >' のインスタンスをスローした後に呼び出された終了 what(): 関数 boost のエラー: :math::tgamma(long double): 負の整数 0 での tgamma の評価。中止 (コアダンプ)

階乗ブースト: 階乗
ブースト tgamma ブースト: tgamma ブースト

私の質問:

  1. 負のドメインのガンマ関数を計算できるブーストの代替手段はありますか?
  2. 階乗と tgamma 関数の実装されたドメインについての言及の上にリンクされているブーストのドキュメントで見つけることができませんでした。実際、私は単にそれらを間違って使用している可能性があります。実際にドメイン/正しい使用法を確認する方法は何ですか?

ありがとう。

4

3 に答える 3