LoginSignup
1
1

More than 1 year has passed since last update.

Γx の 計算方法(Python)

Posted at

今回はhmathで使用されている$\Gamma x$(Gamma(x))の計算方法をご紹介します。

計算式

hmathは次の数式で$\Gamma x$を定義しています。

\begin{eqnarray}
\Gamma x =
\begin{cases}
\frac {\pi}{\sin(\pi x)\Gamma (1-x)} & if \Re x < 0.5\\
\sqrt \tau (x+6.5)^e(x-0.5)(0.99999999999980993+\frac{676.5203681218851}{x}-\frac{1259.1392167224028}{x+1}+\frac{771.32342877765313}{x+2}-\frac{176.61502916214059}{x+3}+\frac{12.507343278686905}{x+4}-\frac{0.13857109526572012}{x+5}+\frac{9.9843695780195716e-6}{x+6}+\frac{1.5056327351493116e-7}{x+7}) & if 0.5 \leqq \Re x\
\end{cases}
\end{eqnarray} 

$\tau$は$\pi 2$で定義される定数です。

プログラム

hmath内では次のプログラムで計算しています。

Gamma.py
import hmath
__Gamma_list = [
      676.5203681218851      ,
    -1259.1392167224028      ,
      771.32342877765313     ,
     -176.61502916214059     ,
       12.507343278686905    ,
       -0.13857109526572012  ,
        9.9843695780195716e-6,
        1.5056327351493116e-7,
]
def Gamma(x):
    if hmath.real_part(x) < 0.5:
        ans = hmath.pi() / (hmath.sin(hmath.pi() * x) * Gamma(1 - x))
    else:
        y = 0.99999999999980993
        for (i, Gamma_v) in enumerate(__Gamma_list): # enumerateというデータ型はループの回数と要素を合わせて取得できる。
            y += Gamma_v / (x + i)
        t = x + len(__Gamma_list) - 1.5
        ans = hmath.sqrt(hmath.tau()) * t ** (x - 0.5) * hmath.exp(-t) * y
    return ans

最後まで見ていだきありがとうございました。
少し長くなりました。
ぜひ活用してみてください。

1
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1