...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Home  Libraries  People  FAQ  More 
boost::numeric::odeint::euler — An implementation of the Euler method.
// In header: <boost/numeric/odeint/stepper/euler.hpp> template<typename State, typename Value = double, typename Deriv = State, typename Time = Value, typename Algebra = range_algebra, typename Operations = default_operations, typename Resizer = initially_resizer> class euler : public boost::numeric::odeint::explicit_stepper_base< Stepper, Order, State, Value, Deriv, Time, Algebra, Operations, Resizer > { public: // types typedef explicit_stepper_base< euler< ... >,... > stepper_base_type; 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 euler(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 StateOut, typename StateIn1, typename StateIn2> void calc_state(StateOut &, time_type, const StateIn1 &, time_type, const StateIn2 &, time_type) const; template<typename StateType> void adjust_size(const StateType &); template<typename System, typename StateInOut> void do_step(System, StateInOut &, time_type, time_type); template<typename System, typename StateInOut> void do_step(System, const StateInOut &, time_type, time_type); template<typename System, typename StateInOut, typename DerivIn> boost::disable_if< boost::is_same< DerivIn, time_type >, void >::type do_step(System, StateInOut &, const DerivIn &, time_type, time_type); template<typename System, typename StateIn, typename StateOut> void do_step(System, const StateIn &, time_type, StateOut &, time_type); template<typename System, typename StateIn, typename DerivIn, typename StateOut> void do_step(System, const StateIn &, const DerivIn &, time_type, StateOut &, time_type); template<typename StateIn> void adjust_size(const StateIn &); const algebra_type & algebra() const; };
The Euler method is a very simply solver for ordinary differential equations. This method should not be used for real applications. It is only useful for demonstration purposes. Step size control is not provided but trivial continuous output is available.
This class derives from explicit_stepper_base and inherits its interface via CRTP (current recurring template pattern), see explicit_stepper_base
typename State
The state type.
typename Value = double
The value type.
typename Deriv = State
The type representing the time derivative of the state.
typename Time = Value
The time representing the independent variable  the time.
typename Algebra = range_algebra
The algebra type.
typename Operations = default_operations
The operations type.
typename Resizer = initially_resizer
The resizer policy type.
euler
public
construct/copy/destructeuler(const algebra_type & algebra = algebra_type());Constructs the euler class. This constructor can be used as a default constructor of the algebra has a default constructor.
Parameters: 

euler
public member functionstemplate<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.
Parameters: 

template<typename StateOut, typename StateIn1, typename StateIn2> void calc_state(StateOut & x, time_type t, const StateIn1 & old_state, time_type t_old, const StateIn2 & current_state, time_type t_new) const;This method is used for continuous output and it calculates the state
x
at a time t
from the knowledge of two states old_state
and current_state
at time points t_old
and t_new
. template<typename StateType> void adjust_size(const StateType & x);Adjust the size of all temporaries in the stepper manually.
Parameters: 

template<typename System, typename StateInOut> void do_step(System system, StateInOut & x, time_type t, time_type dt);This method performs one step. It transforms the result inplace.
Parameters: 

template<typename System, typename StateInOut> void do_step(System system, const StateInOut & x, time_type t, time_type dt);Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut.
template<typename System, typename StateInOut, typename DerivIn> boost::disable_if< boost::is_same< DerivIn, time_type >, void >::type do_step(System system, StateInOut & x, const DerivIn & dxdt, time_type t, time_type dt);The method performs one step. Additionally to the other method the derivative of x is also passed to this method. It is supposed to be used in the following way:
* sys( x , dxdt , t ); * stepper.do_step( sys , x , dxdt , t , dt ); *
The result is updated in place in x. This method is disabled if Time and Deriv are of the same type. In this case the method could not be distinguished from other do_step
versions.
Note  

This method does not solve the forwarding problem. 
Parameters: 

template<typename System, typename StateIn, typename StateOut> void do_step(System system, const StateIn & in, time_type t, StateOut & out, time_type dt);The method performs one step. The state of the ODE is updated outofplace.
Note  

This method does not solve the forwarding problem. 
Parameters: 

template<typename System, typename StateIn, typename DerivIn, typename StateOut> void do_step(System system, const StateIn & in, const DerivIn & dxdt, time_type t, StateOut & out, time_type dt);The method performs one step. The state of the ODE is updated outofplace. Furthermore, the derivative of x at t is passed to the stepper. It is supposed to be used in the following way:
* sys( in , dxdt , t ); * stepper.do_step( sys , in , dxdt , t , out , dt ); *
Note  

This method does not solve the forwarding problem. 
Parameters: 

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

const algebra_type & algebra() const;
Returns: 
A reference to the algebra which is held by this class. A const reference to the algebra which is held by this class. 