4 * Copyright 2011-2013 Mario Mulansky
5 * Copyright 2011-2012 Karsten Ahnert
7 * Distributed under the Boost Software License, Version 1.0.
8 * (See accompanying file LICENSE_1_0.txt or
9 * copy at http://www.boost.org/LICENSE_1_0.txt)
14 #define _USE_MATH_DEFINES
17 #include <boost/array.hpp>
18 #include <boost/ref.hpp>
20 #include <boost/numeric/odeint/config.hpp>
22 #include <boost/numeric/odeint.hpp>
23 #include <boost/numeric/odeint/stepper/bulirsch_stoer.hpp>
24 #include <boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp>
27 using namespace boost::numeric::odeint
;
29 typedef boost::array
< double , 1 > state_type
;
32 * x' = ( - x*sin t + 2 tan x ) y
33 * with x( pi/6 ) = 2/sqrt(3) the analytic solution is 1/cos t
36 void rhs( const state_type
&x
, state_type
&dxdt
, const double t
)
38 dxdt
[0] = ( - x
[0] * sin( t
) + 2.0 * tan( t
) ) * x
[0];
41 void rhs2( const state_type
&x
, state_type
&dxdt
, const double t
)
49 void write_out( const state_type
&x
, const double t
)
51 out
<< t
<< '\t' << x
[0] << endl
;
56 bulirsch_stoer_dense_out
< state_type
> stepper( 1E-8 , 0.0 , 0.0 , 0.0 );
57 bulirsch_stoer
< state_type
> stepper2( 1E-8 , 0.0 , 0.0 , 0.0 );
59 state_type x
= {{ 2.0 / sqrt(3.0) }};
64 double t_end
= M_PI
/2.0 - 0.1;
65 //double t_end = 100.0;
69 integrate_const( stepper
, rhs
, x
, t
, t_end
, dt
, write_out
);
72 x
[0] = 2.0 / sqrt(3.0);
74 out
.open( "bs2.dat" );
76 integrate_adaptive( stepper
, rhs
, x
, t
, t_end
, dt
, write_out
);
79 x
[0] = 2.0 / sqrt(3.0);
81 out
.open( "bs3.dat" );
83 integrate_adaptive( stepper2
, rhs
, x
, t
, t_end
, dt
, write_out
);
87 typedef runge_kutta_dopri5
< state_type
> dopri5_type
;
88 typedef controlled_runge_kutta
< dopri5_type
> controlled_dopri5_type
;
89 typedef dense_output_runge_kutta
< controlled_dopri5_type
> dense_output_dopri5_type
;
91 dense_output_dopri5_type dopri5
= make_dense_output( 1E-9 , 1E-9 , dopri5_type() );
93 x
[0] = 2.0 / sqrt(3.0);
95 out
.open( "bs4.dat" );
97 integrate_adaptive( dopri5
, rhs
, x
, t
, t_end
, dt
, write_out
);