note 61377 added to ref.math

From: Date: Wed, 01 Feb 2006 23:16:59 +0000
Subject: note 61377 added to ref.math
Groups: php.notes 
Request: Send a blank email to php-notes+get-102843@lists.php.net to get a copy of this message
I needed to approximate an integral because i was not able to calculate it, so i wrote this function. It approximates an integral with the composite Simpson's rule. More information on Simpson's rule: http://en.wikipedia.org/wiki/Simpson%27s_rule <?php function simpsonf($x){ // returns f(x) for integral approximation with composite Simpson's rule return(pow((1+pow($x, (-4))), 0.5)); } function simpsonsrule($a, $b, $n){ // approximates integral_a_b f(x) dx with composite Simpson's rule with $n intervals // $n has to be an even number // f(x) is defined in "function simpsonf($x)" if($n%2==0){ $h=($b-$a)/$n; $S=simpsonf($a)+simpsonf($b); $i=1; while($i <= ($n-1)){ $xi=$a+$h*$i; if($i%2==0){ $S=$S+2*simpsonf($xi); } else{ $S=$S+4*simpsonf($xi); } $i++; } return($h/3*$S); } else{ return('$n has to be an even number'); } } ?> ---- Server IP: 64.246.30.37 Probable Submitter: 84.150.120.239 ---- Manual Page -- http://www.php.net/manual/en/ref.math.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61377 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61377&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61377&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61377&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61377&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61377&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61377&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61377&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61377&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102843) next »