GSL::Odeiv::System
GSL::Odeiv::Step
GSL::Odeiv::Control
GSL::Odeiv::Evolve
GSL::Odeiv::Solver
The lowest level components are the stepping functions which advance a solution from time t to t+h for a fixed step-size h and estimate the resulting local error.
GSL::Odeiv::Step.new(T, dim)
GSL::Odeiv::Step#reset
GSL::Odeiv::Step#name
Returns the name of the stepper as a String. For example,
require("gsl") include GSL s = Odeiv::Step.new(Odeiv::RK4, 2) printf("step method is '%s'\n", s.name)
would print something like step method is 'rk4'.
GSL::Odeiv::Step#order
GSL::Odeiv::Step#apply(t, h, y, yerr, dydt_in, dydt_out, sys)
GSL::Odeiv::Step#apply(t, h, y, yerr, dydt_in, sys)
GSL::Odeiv::Step#apply(t, h, y, yerr, sys)
nil
it should be a GSL::Vector object
containing the derivatives for the system at time t on input.
This is optional as the derivatives will be computed internally if they
are not provided, but allows the reuse of existing derivative information.
On output the new derivatives of the system at time t+h will be
stored in dydt_out if it is not nil.GSL::Odeiv::System.new(func, jac, dim)
GSL::Odeiv::System.new(func, dim)
Constructor. This defines a general ODE system with the dimension dim.
ex)
# t: variable (scalar) # y: vector # dydt: vector # params: scalar or an array func = Proc.new { |t, y, dydt, params| mu = params dydt[0] = y[1] dydt[1] = -y[0] - mu*y[1]*(y[0]*y[0] - 1.0) }
The third argument jac is also a Proc objects, to calculate jacobian.
ex)
# t: scalar # y: vector # dfdy: matrix, jacobian # dfdt: vector # params: scalar of an array jac = Proc.new { |t, y, dfdy, dfdt, params| mu = params dfdy.set(0, 0, 0.0) dfdy.set(0, 1, 1.0) dfdy.set(1, 0, -2*mu*y[0]*y[1] - 1.0) dfdy.set(1, 1, -mu*(y[0]*y[0] - 1.0)) dfdt[0] = 0.0 dfdt[1] = 0.0 }
Note that some of the simpler solver algorithms do not make use of the Jacobian matrix, so it is not always strictly necessary to provide it. Thus the constructor is called as
sys = GSL:Odeiv::System.new(func, jac, dim) # for "BSIMP" algorithm sys = GSL:Odeiv::System.new(func, nil, dim) # for others, replaced by nil sys = GSL:Odeiv::System.new(func, dim) # or omit
GSL::Odeiv::System#set(func, jac, parameters...)
GSL::Odeiv::System#set_params(...)
GSL::Odeiv::Control.standard_new(epsabs, epsrel, a_y, a_dydt)
GSL::Odeiv::Control.new(epsabs, epsrel, a_y, a_dydt)
GSL::Odeiv::Control.y_new(epsabs, epsrel)
GSL::Odeiv::Control.yp_new(epsabs, epsrel)
GSL::Odeiv::Control.new(epsabs, epsrel, a_y, a_dydt, vscale, dim)
GSL::Odeiv::Control.standard_new
but with an absolute error which
is scaled for each component by the GSL::Vector object vscale.GSL::Odeiv::Control#init(epsabs, epsrel, a_y, a_dydt)
GSL::Odeiv::Control#name
GSL::Odeiv::Control#hadjust(step, y0, yerr, dydt, h)
GSL::ODEIV::HADJ_DEC
. If the error is sufficiently small then
h may be increased and GSL::ODEIV::HADJ_INC
is returned.
The function returns GSL::ODEIV::HADJ_NIL
if the step-size is
unchanged. The goal of the function is to estimate the largest step-size
which satisfies the user-specified accuracy requirements for the current
point. NOTE, h will be modified.The higher level of the system is the GSL::Evolve class which combines the
results of a stepper and controler to reliably advance the solution forward
over an interval (t_0, t_1)
. If the controler signals that the step-size
should be decreased the GSL::Evolve object backs out of the current step and
tries the proposed smaller step-size. This process is continued until an
acceptable step-size is found.
GSL::Odeiv::Evolve.new(dim)
GSL::Odeiv::Evolve.alloc(dim)
GSL::Odeiv::Evolve#reset
GSL::Odeiv::Evolve#apply(evolve, control, step, sys, t, t1, h, y)
This is the highest level interface to solve ODE system, which contains System, Step, Control, and Evolve classes.
GSL::Odeiv::Solver.new(T, cary, fac, jac, dim)
GSL::Odeiv::Solver.new(T, cary, fac, dim)
This creates a ODE solver with the algorithm type T for the system of dimention dim. Here cary is an array as an argument for the GSL::Odeive:Control
constructor.
ex1)
gos = GSL::Odeiv::Solver.new(GSL::Odeiv::RKF45, [1e-6, 0.0], func, dim)
ex2)
gos = GSL::Odeiv::Solver.new(GSL::Odeiv::BSIMP, [1e-6, 0.0, 1, 0], func, jac, dim)
GSL::Odeiv:::Solver#reset
GSL::Odeiv:::Solver#step
GSL::Odeiv:::Solver#control
GSL::Odeiv:::Solver#evolve
GSL::Odeiv:::Solver#system
GSL::Odeiv::System#set_params(...)
GSL::Odeiv:::Solver#apply(t, t1, h, y)
The following program solves the second-order nonlinear Van der Pol oscillator equation, as found in the GSL manual, x"(t) + \mu x'(t) (x(t)^2 - 1) + x(t) = 0,
This can be converted into a first order system suitable for use with the routines described in this chapter by introducing a separate variable for the velocity, y = x'(t),
y' = -x + \mu y (1-x^2)
require("gsl") include GSL dim = 2 # dimension of the system # Proc object to calculate the derivatives func = Proc.new { |t, y, dydt, mu| dydt[0] = y[1] dydt[1] = -y[0] - mu*y[1]*(y[0]*y[0] - 1.0) } # Create the solver solver = Odeiv::Solver.new(Odeiv::STEP_RKF45, [1e-6, 0.0], func, dim) mu = 10.0 solver.set_params(mu) t = 0.0 # initial time t1 = 100.0 # end time h = 1e-6 # initial step y = Vector.new([1.0, 0.0]) # initial value while t < t1 status = solver.apply(t, t1, h, y) break if status != GSL::SUCCESS printf("%.5e %.5e %.5e %.5e\n", t, y[0], y[1], h) end