Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function simpson($a,$b,$n) {
- $s = 0;
- $h = ($b - $a) / $n;
- for($i = 0; $i <= $n; $i++) {
- $x = $a + $i * $h;
- if (($i == 0) || ($i == n)) {
- $s += sqrt(1 - ($x * $x));
- }
- else {
- if ($i % 2) {
- $s += 2 * sqrt(1 - ($x * $x));
- }
- else {
- $s += 4 * sqrt(1 - ($x * $x));
- }
- }
- }
- return $s * ($h / 3.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement