= $_REQUEST['to']) { echo "Interval out of Order"; return; } if ($_REQUEST['num'] == 0) { echo "Enter Number of points at N:"; return; } $n = $_REQUEST['num']; if ($n > 20) { echo "Maximum 20 points"; return; } if ($n < 2) { echo "Minimum 2 points"; return; } for($i=0;$i<$n;$i++) { if ($_REQUEST['data'][$i] === '') { echo "Missing Data Item "; echo $i+1; return; } } switch($_REQUEST['rad']) { case 'l': calculate_left(); break; case 'r': calculate_right(); break; case 't': calculate_trap(); break; case 's': calculate_simp(); break; default: echo("Choose Type"); } } function calculate_left() { $data = $_REQUEST['data']; $n = $_REQUEST['num']; $from = $_REQUEST['from']; $to = $_REQUEST['to']; $delta = ($to-$from)/($n-1); $amount = 0; for($i=0;$i<$n-1;$i++) { $amount += ($data[$i] * $delta); } echo "Value: " . $amount . "
\n"; } function calculate_right() { $data = $_REQUEST['data']; $n = $_REQUEST['num']; $from = $_REQUEST['from']; $to = $_REQUEST['to']; $delta = ($to-$from)/($n-1); $amount = 0; for($i=1;$i<$n;$i++) { $amount += ($data[$i] * $delta); } echo "Value: " . $amount . "
\n"; } function calculate_trap() { $data = $_REQUEST['data']; $n = $_REQUEST['num']; $from = $_REQUEST['from']; $to = $_REQUEST['to']; $delta = ($to-$from)/($n-1); $amount = 0; //echo "FROM: " . $from . " TO:" . $to . " N:" . $n . " DELTA:" . $delta . "
"; for($i=0;$i<($n-1);$i++) { $amount += (($data[$i]+$data[$i+1])/2 * $delta); } echo "Value: " . $amount . "
\n"; } function calculate_simp() { $data = $_REQUEST['data']; $n = $_REQUEST['num']; $from = $_REQUEST['from']; $to = $_REQUEST['to']; $delta = ($to-$from)/($n-1); $amount = 0; if ($n < 3) { echo "Simpson Rule requires at least 3 data points
\n"; return; } if (($n & 1) == 0) { echo "Simpson Rule requires an odd number of data points
\n"; return; } for($i=0;$i<$n-1;$i+=2) { $amount += (($data[$i]+$data[$i+1]*4+$data[$i+2])/3 * $delta); } echo "Value: " . $amount . "
\n"; } ?> Numerical Integration
Left: Right: Trapezoid: Simpson:
Interval: [ , ] N: Data Points
1: 2: 3: 4: 5:
6: 7: 8: 9: 10:
11: 12: 13: 14: 15:
16: 17: 18: 19: 20: