Created
February 13, 2014 15:51
-
-
Save anonymous/8977597 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub leftrect(&f, $a, $b, $n) { | |
my $h = ($b - $a) / $n; | |
my $sum = [+] do f($_) for $a, *+$h ... $b-$h; # gets prior def of &f somehow | |
# my $sum = [+] (f($_) for $a, *+$h ... $b-$h); # works | |
$h * $sum; | |
} | |
sub tryem(&f, $a, $b, $n, $exact) { | |
say ' exact result: ', $exact; | |
say ' rectangle method left: ', leftrect &f, $a, $b, $n; | |
} | |
tryem { $_ ** 3 }, 0, 1, 100, 0.25; | |
tryem { 1 / $_ }, 1, 100, 100, log(100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment