PDL::RungeKutta - Solve N-th order M dimensional ordinary differential equations using adaptive stepsize Runge Kutta method.
This module allows to solve N-th order M dimensional ordinary differential equations. It uses the adaptive stepsize control for fifth order Cash-Karp Runge-Kutta algorithm described in "Numerical Recipes in Fortran 77: The Art of Scientific Computing" Ch. 16.2. The errors are estimated as the difference between fifth order results and the embeded forth order results. To solve N-th order equations, you must first turn it into a system of N first order equations.
Example: Solve y'' + y = 0, y(0) = 0, y'(0) = 1
use PDL; use PDL::Math; use PDL::NiceSlice; use PDL::RungeKutta; # y'' + y = 0, Solution: y = sin(t) $Y0 = pdl(0,1); # y(0)=0, y'(0)=1 ( Y0=(f,g), f=y, g=y' ) @esargs=(); # extra arguments for error eval function $t0 = 0; # initial moment $dt0 = 0.1; # initial time step $t1 = 1 0; # final moment $eps = 1.e-6; # error $verbose=1; # integration ($evt,$evy,$evd,$i,$j) = rkevolve($t0,$Y,$dt0,\&DE,$t1,$eps,\&error,\@esargs,$verbose); $check=sin($evt); wcols $evt,$evy((0)),$check,'test.dat'; sub DE { # differential eq my ($t,$y)= @_; my $yd=zeroes(2); # Y' ( = (f',g') = (y',y'') ) $yd(0).=$y(1); # f'=g ( = y' ) $yd(1).=-$y(0); # g'=-f ( =-y ) return $yd; } sub error { # error scale my ($t,$Y) = @_; my $es=ones(2); # constant scale return $es; }
Please see the other examples also.
($t,$Y,$d,$i,$j) = rkevolve($t0,$Y0,$dt0,$DE,$t1,$eps,$erfcn,$efarg,$verbose)
This will solve the differential equation for DE with the initial conditions Y0 between t0 and t1 using adaptive step size control for Runge-Kutta.
($y,$del) = rk5($t,$yi,$h,$DE)
This will carry out one Cash-Karp Runge-Kutta step. Could be useful if you want to do your own step size control or you just want equal steps.
Dragos Constantinescu <dragos@venus.nipne.ro>
Math::ODE(3)
"Numerical Recipes in Fortran 77: The Art of Scientific Computing" Ch. 16.
http://lib-www.lanl.gov/numerical/index.html
Copyright (c) 2003 by Dragos Constantinescu. All rights reserved.
This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
24 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
Expected text after =item, not a bullet
You forgot a '=back' before '=head2'
You forgot a '=back' before '=head1'
To install PDL::RungeKutta, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PDL::RungeKutta
CPAN shell
perl -MCPAN -e shell install PDL::RungeKutta
For more information on module installation, please visit the detailed CPAN module installation guide.