note 101047 rejected from function.stats-stat-percentile by thiago
| From: | thiago@php.net | Date: | Tue, 23 Nov 2010 03:37:23 +0000 |
| Subject: | note 101047 rejected from function.stats-stat-percentile by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174277@lists.php.net to get a copy of this message | ||
Note Submitter: jess at jick dot net
----
The erf(x) example offered is a little imprecise for my needs. Here is an adaptation for PHP of one
I found on a Python site:
function erf($x) { // Unreliable for $x >= sqrt(3)
$u0 = $x;
$u1 = -$x*$x*$x/3.;
$n = 0;
$r = $u0;
while ( abs($u0) > abs($u1) ) {
$n += 1;
$u0 = $u1;
$u1 = -$u0*$x*$x*(2*$n+1)/(($n+1)*(2*$n+3));
$r += $u0;
}
if ( $x > sqrt(3.0) ) {
echo "
<P>This version of the \"exact\" erf(<i>x</i>)
only works for <i>x</i> <= sqrt(3)!<P>
";
}
return (2/sqrt(M_PI))*$r;
}
Note the warning message.