# 第1種不完全ガンマ関数 Incomplete Gamma Function Of The First Kind # 引数 値 値 ($A, $X) # 戻り値 第1種不完全ガンマ関数 ($IncompleteGammaFunction) sub COMPLEMENTARYERRORFUNCTIONFIRST{ my ($A, $X) = @_; my $IncompleteGammaFunction = 0; my $IncompleteGamma = 0; my $PrevIncompleteGamma = 0; my $Factorial = 1; my $Num = 0; my $Den = 1; my $Sum = 0; my $Sign = 0; my $Limit = 100; my $Epsilon = 1.0e-10; # 値の確認 if($X < 0){ return 0; } if($X == 0){ # 第1種不完全ガンマ関数 Incomplete Gamma Function Of The First Kind $IncompleteGammaFunction = 0; return $IncompleteGammaFunction; }elsif($N == 1) { # 第1種不完全ガンマ関数 Incomplete Gamma Function Of The First Kind $IncompleteGammaFunction = (1 - exp(-$X)); return $IncompleteGammaFunction; } if(($A > 0) && (($A - int($A)) == 0)){ # 正の整数 for(my $i = 0; $i < $A; $i++){ # 階乗 $Factorial = ($i == 0 ? 1 : $Factorial * $i); # 分子 $Num = $X ** $i; # 分母 $Den = $Factorial; $Sum += ($Num / $Den); } # 第1種不完全ガンマ関数 Incomplete Gamma Function Of The First Kind $IncompleteGamma = $Factorial * (1 - (exp(-$X) * $Sum)); }else { for(my $i = 0; $i < $Limit; $i++){ # 符号 $Sign = (($i % 2) == 0 ? 1: -1); # 分子 $Num = $X ** $i; # 分母 $Den = $A + $i; # 階乗 $Factorial = ($i == 0 ? 1 : $Factorial * $i); # 一つ前 $PrevIncompleteGamma = $IncompleteGamma; # 第1種不完全ガンマ関数 Incomplete Gamma Function Of The First Kind $IncompleteGamma += ($Sign * ($Num / ($Den * $Factorial))); # 収束判定 last if(abs($IncompleteGamma - $PrevIncompleteGamma) < $Epsilon); } # 第1種不完全ガンマ関数 Incomplete Gamma Function Of The First Kind $IncompleteGamma = ($X ** $A) * $IncompleteGamma } # 第1種不完全ガンマ関数 Incomplete Gamma Function Of The First Kind $IncompleteGammaFunction = $IncompleteGamma; return $IncompleteGammaFunction; }