← Main book chapter 9
Contents / index
Browser back
← Previous chapter
Next chapter →
Laboratory
Memory
Cards
Sort
Match
Visuals
Coding
Quiz
Programming practice
Composite Simpson rule — Chapter 9
Force an even number of panels and use alternating weights.
Language:
PHP
Student code
<?php function simpson($f,$a,$b,$n){ $h=($b-$a)/$n; $s=$f($a)+$f($b); for($j=1;$j<$n;$j++) $s += 2*$f($a+$j*$h); return $h*$s/3; } ?>
Check code
Show corrected code
Reset buggy code
Feedback
Corrected code