Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (23 sloc) 806 Bytes
<?
function func ($x,$y){
return sin($x*$y)/(1+sqrt($x*$x+$y*$y))+2;
}
function integratePHP($x0,$xN,$y0,$yN,$iterations){
$result=0;
$time = microtime(true);
for ($i = 0; $i < $iterations; $i++){
for ($j = 0; $j < $iterations; $j++){
//âû÷èñëåíèå êîîðäèíàò òåêóùåãî ïðÿìîóãîëüíèêà
$x = $x0 + ($xN - $x0) / $iterations * $i;
$y = $y0 + ($yN - $y0) / $iterations * $j;
$value = func($x, $y); //âû÷èñëåíèå çíà÷åíèÿ ôóíêöèè
//âû÷èñëåíèå îáúåìà ïàðàëëåëåïèïåäà è ïðèáàâêà ê îáùåìó îáúåìó
$result+=$value*($xN-$x0)*($yN-$y0)/($iterations*$iterations);
}
}
echo ("PHP result = ".$result);
echo ("\nPHP time = ".((microtime(true) - $time)*1000));
echo "\n";
}
integratePHP(-4,4,-4,4,1024);
?>