Standard Deviation

This algorithm calculates the standard deviation of the given set of numbers.



									function StandardDeviation($data)
{
	$mean = 0.0;
	$sumDeviation = 0.0;
	$dataSize = count($data);

	for ($i = 0; $i < $dataSize; $i++)
		$mean += $data[$i];

	$mean = $mean / $dataSize;

	for ($i = 0; $i < $dataSize; $i++)
		$sumDeviation += ($data[$i] - $mean) * ($data[$i] - $mean);

	return sqrt($sumDeviation / $dataSize);
}
								


Example

									$data = array( 13, 23, 12, 44, 55 );
$standardDeviation = StandardDeviation($data);
								


Output

									17.21162397916