Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created December 5, 2013 19:33
Show Gist options
  • Select an option

  • Save xeoncross/7812046 to your computer and use it in GitHub Desktop.

Select an option

Save xeoncross/7812046 to your computer and use it in GitHub Desktop.
<?php
function √($x)
{
return pow($x, 0.5);
}
function ²($x)
{
if (is_array($x)) {
return array_map('²', $x);
}
else {
return pow($x, 2);
}
}
function x̄($x)
{
return Σ($x) / n($x);
}
function Σ($x)
{
return array_sum($x);
}
function n($x)
{
return count($x);
}
function σ($x)
{
return √(1/n($x) * Σ(²($x)) - ²(x̄($x)));
}
echo σ([12, 14, 6.5, 20, 5, 17.5]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment