ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Erf.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 class Erf
8 {
9  private static $twoSqrtPi = 1.128379167095512574;
10 
30  public static function ERF($lower, $upper = null)
31  {
32  $lower = Functions::flattenSingleValue($lower);
33  $upper = Functions::flattenSingleValue($upper);
34 
35  if (is_numeric($lower)) {
36  if ($upper === null) {
37  return self::erfValue($lower);
38  }
39  if (is_numeric($upper)) {
40  return self::erfValue($upper) - self::erfValue($lower);
41  }
42  }
43 
44  return Functions::VALUE();
45  }
46 
59  public static function ERFPRECISE($limit)
60  {
61  $limit = Functions::flattenSingleValue($limit);
62 
63  return self::ERF($limit);
64  }
65 
66  //
67  // Private method to calculate the erf value
68  //
69  public static function erfValue($value)
70  {
71  if (abs($value) > 2.2) {
72  return 1 - ErfC::ERFC($value);
73  }
74  $sum = $term = $value;
75  $xsqr = ($value * $value);
76  $j = 1;
77  do {
78  $term *= $xsqr / $j;
79  $sum -= $term / (2 * $j + 1);
80  ++$j;
81  $term *= $xsqr / $j;
82  $sum += $term / (2 * $j + 1);
83  ++$j;
84  if ($sum == 0.0) {
85  break;
86  }
87  } while (abs($term / $sum) > Functions::PRECISION);
88 
89  return self::$twoSqrtPi * $sum;
90  }
91 }
static ERF($lower, $upper=null)
ERF.
Definition: Erf.php:30
static ERFPRECISE($limit)
ERFPRECISE.
Definition: Erf.php:59
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649