Skip to content

Instantly share code, notes, and snippets.

@ricardofiorani
Created March 18, 2014 01:00
Show Gist options
  • Save ricardofiorani/9611609 to your computer and use it in GitHub Desktop.
Save ricardofiorani/9611609 to your computer and use it in GitHub Desktop.
function faboiola($x, $y) {
$n = count($x);
$soma_x = array_sum($x);
$soma_y = array_sum($y);
$soma_n_x = 0; $xy_sum = 0;
for($i = 0; $i < $n; $i++) {
$xy_sum+=($x[$i]*$y[$i]); $soma_n_x+=($x[$i]*$x[$i]);
}
$m = (($n * $xy_sum) - ($soma_x * $soma_y)) / (($n * $soma_n_x) - ($soma_x * $soma_x)); $b = ($soma_y - ($m * $soma_x)) / $n;
return array("m"=>$m, "b"=>$b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment