Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created May 28, 2013 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/5662919 to your computer and use it in GitHub Desktop.
Save grondilu/5662919 to your computer and use it in GitHub Desktop.
integration failure in perl6
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