lorenz.cpp 765 B

12345678910111213141516171819202122232425262728293031
  1. #include <iostream>
  2. #include <boost/array.hpp>
  3. #include <boost/numeric/odeint.hpp>
  4. using namespace std;
  5. using namespace boost::numeric::odeint;
  6. const double sigma = 10.0;
  7. const double R = 28.0;
  8. const double b = 8.0 / 3.0;
  9. typedef boost::array< double , 3 > state_type;
  10. void lorenz( const state_type &x , state_type &dxdt , double t )
  11. {
  12. dxdt[0] = sigma * ( x[1] - x[0] );
  13. dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
  14. dxdt[2] = -b * x[2] + x[0] * x[1];
  15. }
  16. void write_lorenz( const state_type &x , const double t )
  17. {
  18. cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << endl;
  19. }
  20. int main(int argc, char **argv)
  21. {
  22. state_type x = {{ 10.0 , 1.0 , 1.0 }}; // initial conditions
  23. integrate( lorenz , x , 0.0 , 25.0 , 0.1 , write_lorenz );
  24. }