pBook‎ > ‎BOOST C++‎ > ‎

Solving ODE Boost Lib (odeint)


odeint did undergo the boost review process in the end of September 2012, which means users and other library authors evaluate the code and provide a review report. Based on these reports, odeint was accepted and thus will become part of theboost library collection. That means odeint will be officially shipped with one of the next releases of boost!

Thanks to Steven Watanabe for managing the review and to everyone who participated by providing comments or even a whole review report. We are very proud to contribute a high quality, modern and stable numerical library into boost.


Example: 

#include <iostream>
#include <boost/numeric/odeint.hpp>


using namespace std;
using namespace boost::numeric::odeint;


/* we solve the simple ODE x' = 3/(2t^2) + x/(2t)
 * with initial condition x(1) = 0.
 * Analytic solution is x(t) = sqrt(t) - 1/t
 */

void rhs( const double x , double &dxdt , const double t )
{
    dxdt = 3.0/(2.0*t*t) + x/(2.0*t);
}

void write_cout( const double &x , const double t )
{
    cout << t << '\t' << x << endl;
}

// state_type = double
typedef runge_kutta_dopri5< double > stepper_type;

int main()
{
    double x = 0.0;    
    integrate_adaptive( make_controlled( 1E-12 , 1E-12 , stepper_type() ) ,
                        rhs , x , 1.0 , 10.0 , 0.1 , write_cout );
}