Runge-Kutta method: Difference between revisions
Content deleted Content added
m →{{header|Python}}: style |
→{{header|Perl 6}}: clearer version |
||
Line 562:
{{trans|Perl}}
<lang perl6>sub runge-kutta(&yp
return -> \t, \y, \δt {
my $b = δt * yp( t + δt/2, y + $a/2 );
my $d = δt * yp( t + δt, y + $c );
($a + 2*($b + $c) + $d) / 6;
}
}
constant δt = .1;
my &RK = runge-kutta { $^t * sqrt($^y) }
loop ( my ($t, $y) = (0, 1); $t <= 10; ($t, $y) = RK($t, $y)) {▼
loop (
printf "y(%2d) = %12f ± %e\n", $t, $y, abs($y - ($t**2 + 4)**2 / 16)▼
my ($t, $y) = (0, 1);
$t <= 10;
) {
if $t == $t.Int;
}</lang>
|