Runge-Kutta method: Difference between revisions
Content deleted Content added
m →{{header|Perl}}: rephrasing |
|||
Line 458: | Line 458: | ||
my ($yp, $t, $y, $dt) = @_; |
my ($yp, $t, $y, $dt) = @_; |
||
sub { |
sub { |
||
⚫ | |||
my @dy; |
|||
⚫ | |||
push @dy, $dt * $yp->( $t + $dt/2, $y + $dy[0]/2 ); |
push @dy, $dt * $yp->( $t + $dt/2, $y + $dy[0]/2 ); |
||
push @dy, $dt * $yp->( $t + $dt/2, $y + $dy[1]/2 ); |
push @dy, $dt * $yp->( $t + $dt/2, $y + $dy[1]/2 ); |
||
push @dy, $dt * $yp->( $t |
push @dy, $dt * $yp->( $t += $dt, $y + $dy[2] ); |
||
return $y += (@dy[0] + 2*$dy[1] + 2*$dy[2] + $dy[3]) / 6; |
return $y += (@dy[0] + 2*$dy[1] + 2*$dy[2] + $dy[3]) / 6; |
||
} |
} |