Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
Boost C++ Libraries Home Libraries People FAQ More


Class template runge_kutta4

boost::numeric::odeint::runge_kutta4 — The classical Runge-Kutta stepper of fourth order.


// In header: <boost/numeric/odeint/stepper/runge_kutta4.hpp>

template<typename State, typename Value = double, typename Deriv = State, 
         typename Time = Value, 
         typename Algebra = typename algebra_dispatcher< State >::algebra_type, 
         typename Operations = typename operations_dispatcher< State >::operations_type, 
         typename Resizer = initially_resizer> 
class runge_kutta4 : public boost::numeric::odeint::explicit_generic_rk< StageCount, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer >
  // types
  typedef stepper_base_type::state_type      state_type;     
  typedef stepper_base_type::value_type      value_type;     
  typedef stepper_base_type::deriv_type      deriv_type;     
  typedef stepper_base_type::time_type       time_type;      
  typedef stepper_base_type::algebra_type    algebra_type;   
  typedef stepper_base_type::operations_type operations_type;
  typedef stepper_base_type::resizer_type    resizer_type;   

  // construct/copy/destruct
  runge_kutta4(const algebra_type & = algebra_type());

  // public member functions
  template<typename System, typename StateIn, typename DerivIn, 
           typename StateOut> 
    void do_step_impl(System, const StateIn &, const DerivIn &, time_type, 
                      StateOut &, time_type);
  template<typename StateIn> void adjust_size(const StateIn &);


The Runge-Kutta method of fourth order is one standard method for solving ordinary differential equations and is widely used, see also The method is explicit and fulfills the Stepper concept. Step size control or continuous output are not provided.

This class derives from explicit_stepper_base and inherits its interface via CRTP (current recurring template pattern). Furthermore, it derivs from explicit_generic_rk which is a generic Runge-Kutta algorithm. For more details see explicit_stepper_base and explicit_generic_rk.

Template Parameters

  1. typename State

    The state type.

  2. typename Value = double

    The value type.

  3. typename Deriv = State

    The type representing the time derivative of the state.

  4. typename Time = Value

    The time representing the independent variable - the time.

  5. typename Algebra = typename algebra_dispatcher< State >::algebra_type

    The algebra type.

  6. typename Operations = typename operations_dispatcher< State >::operations_type

    The operations type.

  7. typename Resizer = initially_resizer

    The resizer policy type.

runge_kutta4 public construct/copy/destruct

  1. runge_kutta4(const algebra_type & algebra = algebra_type());
    Constructs the runge_kutta4 class. This constructor can be used as a default constructor if the algebra has a default constructor.



    A copy of algebra is made and stored inside explicit_stepper_base.

runge_kutta4 public member functions

  1. template<typename System, typename StateIn, typename DerivIn, 
             typename StateOut> 
      void do_step_impl(System system, const StateIn & in, const DerivIn & dxdt, 
                        time_type t, StateOut & out, time_type dt);
    This method performs one step. The derivative dxdt of in at the time t is passed to the method. The result is updated out of place, hence the input is in in and the output in out. Access to this step functionality is provided by explicit_stepper_base and do_step_impl should not be called directly.



    The step size.


    The derivative of x at t.


    The state of the ODE which should be solved. in is not modified in this method


    The result of the step is written in out.


    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.


    The value of the time, at which the step should be performed.

  2. template<typename StateIn> void adjust_size(const StateIn & x);
    Adjust the size of all temporaries in the stepper manually.



    A state from which the size of the temporaries to be resized is deduced.