Skip to content

Instantly share code, notes, and snippets.

@gollilla
Created May 9, 2019 01:00
Show Gist options
  • Save gollilla/0e85c591d79adae69ea65bdc1eedfa2e to your computer and use it in GitHub Desktop.
Save gollilla/0e85c591d79adae69ea65bdc1eedfa2e to your computer and use it in GitHub Desktop.
<?php
// https://paiza.io/projects/szvtfJnxiwMhun_ndDxs6w
$a = [4,8,16,32,64,900];
for($i=0;$i<count($a);$i++){
$h = 1 / $a[$i];
$y0 = y(0);
$yn = y(1);
$x = 0;
$y = 0;
for($j=0;$j<$a[$i] - 2;$j++){
$x += $h;
$y += y($x);
}
echo "n=", $a[$i], "I=" , ($h / 2)*($y0+$yn+2*$y);
echo PHP_EOL;
}
function y($x){
return (1 / (1 + $x**2));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment