MathPHP\Functions\Special::lowerIncompleteGamma PHP Метод

lowerIncompleteGamma() публичный статический Метод

This function is exact for all integer multiples of .5 using the recurrance relation: γ⟮s+1,x⟯= s*γ⟮s,x⟯-xˢ*eˣ The function can be evaluated at other points using the series: zˢ / x x² x³ \ γ(s,x) = -------- | 1 + ----- + ---------- + --------------- + ... | s * eˣ \ s+1 (s+1)(s+2) (s+1)(s+2)(s+3) /
public static lowerIncompleteGamma ( $s, $x ) : number
$s
$x
Результат number
    public static function lowerIncompleteGamma($s, $x)
    {
        if ($s == 1) {
            return 1 - exp(-1 * $x);
        }
        if ($s == 0.5) {
            $√π = sqrt(\M_PI);
            $√x = sqrt($x);
            return $√π * self::erf($√x);
        }
        if (round($s * 2, 0) == $s * 2) {
            return ($s - 1) * self::lowerIncompleteGamma($s - 1, $x) - $x ** ($s - 1) * exp(-1 * $x);
        }
        $tol = 1.0E-12;
        $xˢ∕s∕eˣ = $x ** $s / exp($x) / $s;
        $sum = 1;
        $fractions = [];
        $element = 1 + $tol;
        while ($element > $tol) {
            $fractions[] = $x / ++$s;
            $element = array_product($fractions);
            $sum += $element;
        }
        return $xˢ∕s∕eˣ * $sum;
    }