Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 49 lines (33 sloc) 1.261 kb
2def80a9 »
2010-06-02 README
1 Runge-Kutta integration for systems of ordinary, linear differential
2 equations.
3
4 WARNING: this module is not yet thoroughly tested. Use it at your own risk.
5 Bug reports, tests and patches are welcome!
6
7 Let's say you have a differential equation for the function f(t),
8 with the equation
9
10 df/dt = f(t)^2 + t
11 and the initial value f(t=0) = 1;
12
13 In the context of this module, we call df/dt the "derivative",
14 t the "parameter"
15
16 You'd solve that numerically with this Perl 6 code:
17
18 # begin synopsis.pl
19
20 use Math::RungeKutta;
21
22 # function that calculates the derivative
23 sub d($t, @values) { @values[0]**2 + $t}
24
25 # that's a function that gets called with the
26 # current values after each integration step
27 sub callback($t, @values) { say "$t @values[0]" };
28
29 my @initial = 1;
30
c638605c »
2010-06-13 implement adaptive step size
31 adaptive-rk-integrate(
2def80a9 »
2010-06-02 README
32 :from(0),
33 :to(0.5),
34 :@initial,
35 :derivative(&d),
36 :do(&callback)
37 );
38
39 # end synopsis.pl
40
41 And then look at the result:
42 $ PERL6LIB=lib perl6 synopsis.pl | xmgrace -nxy -
43
44 The interfaces is inspired by Perl 5 module Math::RungeKutta, to be found at
45 <http://search.cpan.org/perldoc?Math::RungeKutta>.
f62a0320 »
2011-02-13 [README] mention that it works Right Now
46
47 Math::RungeKutta has last been verified to work on contemporary rakudo on
48 2011-02-13.
Something went wrong with that request. Please try again.