Created
May 28, 2013 13:56
-
-
Save grondilu/5662919 to your computer and use it in GitHub Desktop.
integration failure in perl6
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 simpsons(&f, $a, $b, $n) { | |
my $h = ($b - $a) / $n; | |
my $h2 = $h/2; | |
my $sum1 = f($a + $h2); | |
my $sum2 = 0; | |
for $a+$h, *+$h ... $b-$h { | |
$sum1 += f($_ + $h2); | |
$sum2 += f($_); | |
} | |
($h / 6) * (f($a) + f($b) + 4*$sum1 + 2*$sum2); | |
} | |
constant R_max = 6.75 / 2; | |
constant Length = 83; | |
sub sears-haack($x, $R) { $R * (4*pi*$x*(1-$x))**(3/4) } | |
say simpsons(&sears-haack.assuming(*, R_max / Length), 0, 1, $_) for <10 100 1000>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment