Advertisement
atm-irbis

Simpson

Apr 25th, 2014
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. function simpson($a,$b,$n) {
  2.   $s = 0;
  3.   $h = ($b - $a) / $n;
  4.   for($i = 0; $i <= $n; $i++) {
  5.     $x = $a + $i * $h;
  6.     if (($i == 0) || ($i == n)) {
  7.       $s += sqrt(1 - ($x * $x));
  8.     }
  9.     else {
  10.       if ($i % 2) {
  11.         $s += 2 * sqrt(1 - ($x * $x));
  12.       }
  13.       else {
  14.         $s += 4 * sqrt(1 - ($x * $x));
  15.       }
  16.     }
  17.   }
  18.   return $s * ($h / 3.0);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement