Class Erf

java.lang.Object
ffx.numerics.special.Erf

public class Erf extends Object
Static methods to evaluate erf(x) and erfc(x) for a real argument x. Rational functions are used that approximate erf(x) and erfc(x) to machine precision (approximately 15 decimal digits).

The error function erf(x) is defined as: erf(x) = (2/sqrt(pi)) * integral from 0 to x of exp(-t^2) dt

The complementary error function erfc(x) is defined as: erfc(x) = 1 - erf(x) = (2/sqrt(pi)) * integral from x to infinity of exp(-t^2) dt

This implementation uses different approximation formulas for different ranges of the input:

  • |x| <= 0.46875: Uses a rational function approximation.
  • 0.46875 < |x| <= 4.0: Uses a rational function approximation for erfc.
  • |x| > 4.0: Uses a rational function approximation for erfc with additional scaling.

Adapted from an original program written by W. J. Cody, Mathematics and Computer Science Division, Argonne National Laboratory, Argonne, IL 60439

Reference: W. J. Cody, "Rational Chebyshev Approximations for the Error Function," Mathematics of Computation, Vol. 23, No. 107 (Jul., 1969), pp. 631-637.

Since:
1.0
Author:
Michael J. Schnieders
  • Method Details

    • erf

      public static double erf(double arg)
      Evaluates erf(x) for a real argument x.

      The error function erf(x) is defined as: erf(x) = (2/sqrt(pi)) * integral from 0 to x of exp(-t^2) dt

      Special cases:

      • If arg is NaN, then the result is NaN.
      • If arg is +infinity, then the result is 1.0.
      • If arg is -infinity, then the result is -1.0.
      • If arg is 0, then the result is 0.
      Parameters:
      arg - the value to evaluate erf at.
      Returns:
      erf of the argument.
      Since:
      1.0
    • erfc

      public static double erfc(double arg)
      Evaluate erfc(x) for a real argument x.

      The complementary error function erfc(x) is defined as: erfc(x) = 1 - erf(x) = (2/sqrt(pi)) * integral from x to infinity of exp(-t^2) dt

      Special cases:

      • If arg is NaN, then the result is NaN.
      • If arg is +infinity, then the result is 0.0.
      • If arg is -infinity, then the result is 2.0.
      • If arg is 0, then the result is 1.0.
      Parameters:
      arg - the value to evaluate erfc at.
      Returns:
      erfc of the argument.
      Since:
      1.0