#include <iostream> #include <boost/numeric/odeint.hpp> // odeint function definitions using namespace std; using namespace boost::numeric::odeint; // Defining a shorthand for the type of the mathematical state typedef std::vector< double > state_type; // System to be solved: dx/dt = -2 x void my_system( const state_type &x , state_type &dxdt , const double t ) { dxdt[0] = -2*x[0]; } // Observer, prints time and state when called (during integration) void my_observer( const state_type &x, const double t ) { std::cout << t << " " << x[0] << std::endl; } // ------ Main int main() { state_type x0(1); // Initial condition, vector of 1 element (scalar problem) x0[0] = 10.0; // Integration parameters double t0 = 0.0; double t1 = 10.0; double dt = 0.1; // Run integrator integrate( my_system, x0, t0, t1, dt, my_observer ); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)