private static DoubleDouble Erfc_ContinuedFraction(DoubleDouble x) { DoubleDouble x2 = x * x; double aa = 1.0; DoubleDouble bb = x2 + 0.5; DoubleDouble D = 1.0 / bb; DoubleDouble Df = aa / bb; DoubleDouble f = Df; for (int k = 1; k < 100; k++) { DoubleDouble f_old = f; aa = -k * (k - 0.5); bb += 2.0; D = 1.0 / (bb + aa * D); Df = (bb * D - 1.0) * Df; f += Df; if (f == f_old) { DoubleDouble e = DoubleDouble.Exp(-x2); DoubleDouble g = x / DoubleDouble.Sqrt(DoubleDouble.Pi); return(e * f * g); } } throw new InvalidOperationException(); }
private static DoubleDouble Erf_Series(DoubleDouble x) { DoubleDouble mx2 = -(x * x); DoubleDouble t = DoubleDouble.One; DoubleDouble f = t; for (int k = 1; k < 100; k++) { DoubleDouble f_old = f; t *= mx2 / k; f += t / (2 * k + 1); if (f == f_old) { return((2.0 / DoubleDouble.Sqrt(DoubleDouble.Pi)) * x * f); } } throw new InvalidOperationException(); }