This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ODEs - runge kutta



This is slightly OT, and I don't mean to toot my own horn, but
if you would like to use Perl, I wrote the Math::ODE perl module
for this situation. It uses the 4th Order Runge-Kutta, and does the
jacobian approximation by itself, so that all you do is define all the
parameters of the system. 

Example:
---begin code---
#!/usr/bin/perl -w

# Example 1: Solve  f'' - g' = 0        
#                   g'' + f*g' + f'*g = 0
#                   f(0)=0,f'(0)=1,f''(0)=-1,g(0)=1
#            Solution: f = 1 - exp(-x)
#                      g = exp(-x)
use Math::ODE;
my $o = new Math::ODE ( file => 'data',
                        step => 0.1,
                        initial => [0,1,-1,1],
                        DE => [ \&DE1, \&DE2 , \&DE3, \&DE4 ],
                        t0 => 0,
                        tf => 20 );
$o->evolve;
# define the system
sub DE1 { my ($t,$y) = @_; return $y->[1]; }
sub DE2 { my ($t,$y) = @_; return $y->[2]; }
sub DE3 { my ($t,$y) = @_; return $y->[1] * $y->[3] - $y->[0] * $y->[2]; }
sub DE4 { my ($t,$y) = @_; return $y->[2]; }
-----end code----

It is available at www.cpan.org and http://www.leto.net/code/Math-ODE/ .

Once again, I would like to state that GSL has a much more powerful interface
for solving ODE's, but it is probably overkill in most simle situations, and
not friendly to the beginning programmer.



 Sam Halliday (plendily@hotmail.com) was saying:

> hello,
> 
> i am currently trying to numerically solve the lane-emden equation, which is 
> 
> a 2nd order differential equation, and experience has shown that the 4th 
> order runge kutta is the best way to solve this.
> 
> i was interrested in using the GSL for solving this problem, although the 
> examples section for ODE's scared me too much... must i really define so 
> much, (jacobians and so forth), is there not a way in which i can just send 
> my function, parameter (which actually is the time) and time step length to 
> a library and let it do all the work? does anyone have a simple example i 
> can follow so that i can use this library for this task? teh one in the 
> documenattion seems to be too crypic, and tries to do too much for my 
> needs...
> 
> please respond to me at
> plendily at hotmail dot com
> as i am not subscribed to this list,
> thanks!
> 
> cheers,
> Sam
> ---
> "Anyone can play guitar", Radiohead, 1993
> 
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
> 

-- 
jonathan@leto.net 
"Wir muessen wissen. Wir werden wissen."
	-- David Hilbert



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]