Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-301

Erf(z) should return 1.0 for z 'large' but fails with a MaxIterationsExceededException for z > 26.0.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0
    • 2.1
    • None
    • None
    • MacOS and Linux

    Description

      Erf(z) should return 1.0 for z 'large' but fails with a MaxIterationsExceededException for z > 26.0.

      Sample code
      -----------------

      import org.apache.commons.math.MathException;
      import org.apache.commons.math.special.Erf;

      public class TestErf {

      public TestErf() {
      }

      public static void main(String[] args) {
      double z = Double.NEGATIVE_INFINITY;
      try {
      for(int i=0; i<100; i++)

      { z = i; System.out.println("z = " + z + " erf(z) = " + Erf.erf(z)); }

      System.out.flush();
      } catch (MathException mex)

      { System.out.println("z failed = " + z); mex.printStackTrace(); }

      }
      }

      Output
      ---------

      z = 0.0 erf(z) = 0.0
      z = 1.0 erf(z) = 0.842700792949715
      z = 2.0 erf(z) = 0.9953222650189528
      z = 3.0 erf(z) = 0.9999779095030024
      z = 4.0 erf(z) = 0.9999999845827416
      z = 5.0 erf(z) = 0.9999999999984622
      z = 6.0 erf(z) = 0.9999999999999997
      z = 7.0 erf(z) = 1.000000000000001
      z = 8.0 erf(z) = 0.9999999999999986
      z = 9.0 erf(z) = 1.000000000000003
      z = 10.0 erf(z) = 1.0000000000000115
      z = 11.0 erf(z) = 1.0000000000000016
      z = 12.0 erf(z) = 0.9999999999999941
      z = 13.0 erf(z) = 0.9999999999999846
      z = 14.0 erf(z) = 1.0000000000000024
      z = 15.0 erf(z) = 0.9999999999999805
      z = 16.0 erf(z) = 0.9999999999999988
      z = 17.0 erf(z) = 0.9999999999999949
      z = 18.0 erf(z) = 0.9999999999999907
      z = 19.0 erf(z) = 0.9999999999999731
      z = 20.0 erf(z) = 0.9999999999999862
      z = 21.0 erf(z) = 0.9999999999999721
      z = 22.0 erf(z) = 1.000000000000017
      z = 23.0 erf(z) = 1.0000000000000577
      z = 24.0 erf(z) = 1.000000000000054
      z = 25.0 erf(z) = 1.0000000000000262
      z = 26.0 erf(z) = 1.0000000000000735
      z failed = 27.0
      org.apache.commons.math.MaxIterationsExceededException: Maximal number of iterations (10,000) exceeded
      at org.apache.commons.math.special.Gamma.regularizedGammaP(Gamma.java:181)
      at org.apache.commons.math.special.Erf.erf(Erf.java:51)
      at org.fhcrc.math.minimization.TestErf.main(TestErf.java:23)

      Attachments

        1. erf.txt
          4 kB
          Nipun Jawalkar

        Issue Links

          Activity

            People

              Unassigned Unassigned
              milac Tom Milac
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: