]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* Boost libs/numeric/odeint/examples/integrate_times.cpp |
2 | ||
3 | Copyright 2009-2014 Karsten Ahnert | |
4 | Copyright 2009-2014 Mario Mulansky | |
5 | ||
6 | example for the use of integrate_times | |
7 | ||
8 | Distributed under the Boost Software License, Version 1.0. | |
9 | (See accompanying file LICENSE_1_0.txt or | |
10 | copy at http://www.boost.org/LICENSE_1_0.txt) | |
11 | */ | |
12 | ||
13 | ||
14 | #include <iostream> | |
15 | #include <boost/numeric/odeint.hpp> | |
16 | ||
17 | using namespace std; | |
18 | using namespace boost::numeric::odeint; | |
19 | ||
20 | ||
21 | /* | |
22 | * simple 1D ODE | |
23 | */ | |
24 | ||
25 | void rhs( const double x , double &dxdt , const double t ) | |
26 | { | |
27 | dxdt = 3.0/(2.0*t*t) + x/(2.0*t); | |
28 | } | |
29 | ||
30 | void write_cout( const double &x , const double t ) | |
31 | { | |
32 | cout << t << '\t' << x << endl; | |
33 | } | |
34 | ||
35 | // state_type = double | |
36 | typedef runge_kutta_dopri5< double > stepper_type; | |
37 | ||
38 | const double dt = 0.1; | |
39 | ||
40 | int main() | |
41 | { | |
42 | // create a vector with observation time points | |
43 | std::vector<double> times( 91 ); | |
44 | for( size_t i=0 ; i<times.size() ; ++i ) | |
45 | times[i] = 1.0 + dt*i; | |
46 | ||
47 | double x = 0.0; //initial value x(1) = 0 | |
48 | // we can provide the observation time as a boost range (i.e. the vector) | |
49 | integrate_times( make_controlled( 1E-12 , 1E-12 , stepper_type() ) , rhs , | |
50 | x , times , dt , write_cout ); | |
51 | // or as two iterators | |
52 | //integrate_times( make_controlled( 1E-12 , 1E-12 , stepper_type() ) , rhs , | |
53 | // x , times.begin() , times.end() , dt , write_cout ); | |
54 | } |