Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 31 lines (28 sloc) 933 Bytes
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes qw (time);
sub func {
my ($x, $y) = @_;
return sin($x*$y)/(1+sqrt($x*$x+$y*$y))+2;
}
sub integratePerl{
my ($x0,$xN,$y0,$yN,$iterations) = @_;
my $result=0;
my $_time = time();
my ($i, $j, $x, $y, $value);
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);
}
}
print("Perl(preinit vars) result = ".$result);
print("\nPerl(preinit vars) time = ".((time() - $_time)*1000) );
print "\n";
}
integratePerl(-4,4,-4,4,1024);
Something went wrong with that request. Please try again.