php 计算正态分布函数的累积密度

function getNormalDensity($u_stand){
	if($u_stand<-3.99)return 0;
	if($u_stand>3.99)return 1;
	$foot=-3.99;
	$step=0.01;
	$result=0.000033;
	for($i=$foot+$step;$i<$u_stand;$i+=$step){
		$result+=(1/sqrt(2*pi())*exp(-$i*$i/2)/100);
	}
	return round($result,6);
}
	echo getNormalDensity(-4.00)."<br />";
	echo getNormalDensity(-3.99)."<br />";
	echo getNormalDensity(-3.96)."<br />";  //0.000038
	echo getNormalDensity(-3.49)."<br />";  //0.000245
	echo getNormalDensity(0)."<br />";      //0.501994
	echo getNormalDensity(3.49)."<br />";   //0.999762
	echo getNormalDensity(3.99)."<br />";   //0.999967
	echo getNormalDensity(4.99)."<br />";

误差还是有的

原文地址:https://www.cnblogs.com/frostbelt/p/2420852.html