Math::GSL::ODEIV(3pm)
π NAME π
Math::GSL::ODEIV β bestie, this is the module that solves ordinary differential equation (ODE) initial value problems. It's a Perl wrapper around the GSL ODEIV gang, and it lives in the Math::GSL family of manual pages (the 3pm kind, aka user-contributed Perl docs). π¦
β¨ SYNOPSIS β¨
use Math::GSL::ODEIV qw /:all/;
That's it. One line and you've got the whole toolbox. π
πΈ DESCRIPTION πΈ
Okay so here is a list of all the functions in this module, no gatekeeping, no cap:
gsl_odeiv_step_alloc($T, $dim)β hands you back a pointer to a freshly allocated instance of a stepping function of type$T, for a system with$dimdimensions.
Heads up bestie: $T must be one of the step type constants listed further down this page. π
gsl_odeiv_step_reset($s)β resets the stepping function$s. Use this whenever the next use of$sis not a continuation of a previous step.gsl_odeiv_step_free($s)β frees all the memory associated with the stepping function$s. Let it go, she's done. ποΈgsl_odeiv_step_name($s)β returns a pointer to the name of the stepping function.gsl_odeiv_step_order($s)β returns the order of the stepping function on the previous step. Lowkey flexible: this order can vary if the stepping function itself is adaptive.gsl_odeiv_step_applyβ that's literally all the original doc says about this one. It's listed and that's it. πgsl_odeiv_control_alloc($T)β returns a pointer to a newly allocated instance of a control function of type$T. Fr fr, this one is only needed if you're defining new types of control functions. For most purposes the standard control functions described below are sufficient. And$There is agsl_odeiv_control_type.gsl_odeiv_control_init($c, $eps_abs, $eps_rel, $a_y, $a_dydt)β initializes the control function$cwith these parameters:$eps_abs(absolute error),$eps_rel(relative error),$a_y(scaling factor for y), and$a_dydt(scaling factor for derivatives).gsl_odeiv_control_freeβ listed, no description given in the source. That's the whole vibe. πgsl_odeiv_control_hadjustβ also just listed, no prose attached.gsl_odeiv_control_nameβ same situation, name only.gsl_odeiv_control_standard_new($eps_abs, $eps_rel, $a_y, $a_dydt)β the standard control object is a four parameter heuristic based on the absolute and relative errors$eps_absand$eps_rel, plus scaling factors$a_yand$a_dydtfor the system statey(t)and derivativesy'(t)respectively. Okay buckle up, here's the procedure:
The step-size adjustment begins by computing the desired error level D_i for each component:
D_i = eps_abs + eps_rel * (a_y |y_i| + a_dydt h |y'_i|)
and comparing it with the observed error E_i = |yerr_i|.
If the observed error E exceeds the desired error level D by more than 10% for any component, then the method reduces the step-size by an appropriate factor:
h_new = h_old * S * (E/D)^(-1/q)
where q is the consistency order of the method (e.g. q=4 for 4(5) embedded RK), and S is a safety factor of 0.9. The ratio E/D is taken to be the maximum of the ratios E_i/D_i.
If the observed error E is less than 50% of the desired error level D for the maximum ratio E_i/D_i, then the algorithm takes the opportunity to increase the step-size to bring the error in line with the desired level:
h_new = h_old * S * (E/D)^(-1/(q+1))
This encompasses all the standard error scaling methods. And to avoid uncontrolled changes in the stepsize, the overall scaling factor is limited to the range 1/5 to 5. π
gsl_odeiv_control_y_new($eps_abs, $eps_rel)β creates a new control object that keeps the local error on each step within an absolute error of$eps_absand a relative error of$eps_relwith respect to the solutiony_i(t). This is equivalent to the standard control object witha_y=1anda_dydt=0.gsl_odeiv_control_yp_new($eps_abs, $eps_rel)β creates a new control object that keeps the local error on each step within an absolute error of$eps_absand a relative error of$eps_relwith respect to the derivatives of the solution,y'_i(t). This is equivalent to the standard control object witha_y=0anda_dydt=1.gsl_odeiv_control_scaled_new($eps_abs, $eps_rel, $a_y, $a_dydt, $scale_abs, $dim)β creates a new control object using the same algorithm asgsl_odeiv_control_standard_new, but with an absolute error that's scaled for each component by the array reference$scale_abs. The formula forD_ifor this control object is:
D_i = eps_abs * s_i + eps_rel * (a_y |y_i| + a_dydt h |y'_i|)
where s_i is the i-th component of the array scale_abs. And the same error control heuristic is used by the Matlab ode suite, so you know it's got pedigree. π
gsl_odeiv_evolve_alloc($dim)β returns a pointer to a newly allocated instance of an evolution function for a system of$dimdimensions.gsl_odeiv_evolve_apply($e, $c, $step, $dydt, \$t, $t1, \$h, $y)β this one advances the system ($e,$dydt) from time$tand position$yusing the stepping function$step. The new time and position get stored in$tand$yon output. The initial step-size is taken as$h, but this will be modified using the control function$cto achieve the appropriate error bound if necessary. The routine may make several calls tostepin order to determine the optimum step-size. If the step-size has been changed, the value of$hwill be modified on output. The maximum time$t1is guaranteed not to be exceeded by the time-step. And on the final time-step, the value of$twill be set to$t1exactly. Clean. β¨gsl_odeiv_evolve_reset($e)β resets the evolution function$e. Use it whenever the next use of$ewill not be a continuation of a previous step.gsl_odeiv_evolve_free($e)β frees all the memory associated with the evolution function$e.
This module also includes the following constants, bestie:
$GSL_ODEIV_HADJ_INC$GSL_ODEIV_HADJ_NIL$GSL_ODEIV_HADJ_DEC
π Step Type π
The step type constants, aka the whole menu of integrators:
$gsl_odeiv_step_rk2β Embedded Runge-Kutta (2, 3) method.$gsl_odeiv_step_rk4β 4th order (classical) Runge-Kutta. The error estimate is obtained by halving the step-size. For a more efficient estimate of the error, use the Runge-Kutta-Fehlberg method described below.$gsl_odeiv_step_rkf45β Embedded Runge-Kutta-Fehlberg (4, 5) method. This method is a good general-purpose integrator.$gsl_odeiv_step_rkckβ Embedded Runge-Kutta Cash-Karp (4, 5) method.$gsl_odeiv_step_rk8pdβ Embedded Runge-Kutta Prince-Dormand (8,9) method.$gsl_odeiv_step_rk2impβ Implicit 2nd order Runge-Kutta at Gaussian points.$gsl_odeiv_step_rk2simpβ yep, it's on the list.$gsl_odeiv_step_rk4impβ Implicit 4th order Runge-Kutta at Gaussian points.$gsl_odeiv_step_bsimpβ Implicit Bulirsch-Stoer method of Bader and Deuflhard. This algorithm requires the Jacobian.$gsl_odeiv_step_gear1βM=1implicit Gear method.$gsl_odeiv_step_gear2βM=2implicit Gear method.
For more information on the functions, we refer you to the GSL official documentation: <http://www.gnu.org/software/gsl/manual/html_node/>
π¦ EXAMPLE π¦
The example is taken from <https://www.math.utah.edu/software/gsl/gsl-ref_367.html>. Run it, it's iconic:
use strict;
use warnings;
use Math::GSL::Errno qw($GSL_SUCCESS);
use Math::GSL::ODEIV qw/ :all /;
use Math::GSL::Matrix qw/:all/;
use Math::GSL::IEEEUtils qw/ :all /;
sub func {
my ($t, $y, $dydt, $params) = @_;
my $mu = $params->{mu};
$dydt->[0] = $y->[1];
$dydt->[1] = -$y->[0] - $mu*$y->[1]*(($y->[0])**2 - 1);
return $GSL_SUCCESS;
}
sub jac {
my ($t, $y, $dfdy, $dfdt, $params) = @_;
my $mu = $params->{mu};
my $m = gsl_matrix_view_array($dfdy, 2, 2);
gsl_matrix_set( $m, 0, 0, 0.0 );
gsl_matrix_set( $m, 0, 1, 1.0 );
gsl_matrix_set( $m, 1, 0, (-2.0 * $mu * $y->[0] * $y->[1]) - 1.0 );
gsl_matrix_set( $m, 1, 1, -$mu * (($y->[0])**2 - 1.0) );
$dfdt->[0] = 0.0;
$dfdt->[1] = 0.0;
return $GSL_SUCCESS;
}
my $T = $gsl_odeiv_step_rk8pd;
my $s = gsl_odeiv_step_alloc($T, 2);
my $c = gsl_odeiv_control_y_new(1e-6, 0.0);
my $e = gsl_odeiv_evolve_alloc(2);
my $params = { mu => 10 };
my $sys = Math::GSL::ODEIV::gsl_odeiv_system->new(\&func, \&jac, 2, $params );
my $t = 0.0;
my $t1 = 100.0;
my $h = 1e-6;
my $y = [ 1.0, 0.0 ];
gsl_ieee_env_setup;
while ($t < $t1) {
my $status = gsl_odeiv_evolve_apply ($e, $c, $s, $sys, \$t, $t1, \$h, $y);
last if $status != $GSL_SUCCESS;
printf "%.5e %.5e %.5e\n", $t, $y->[0], $y->[1];
}
gsl_odeiv_evolve_free($e);
gsl_odeiv_control_free($c);
gsl_odeiv_step_free($s);
π AUTHORS π
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
π COPYRIGHT AND LICENSE π
Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π this was perl v5.42.3, dated 2026-08-20, and it's the Math::GSL::ODEIV(3pm) manual page from the user-contributed Perl documentation. go integrate something, main character π«Άβ¨
π¦ where this page comes from
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms