fork(2) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. using namespace boost::numeric::odeint;
  5.  
  6.  
  7. const double sigma = 10.0;
  8. const double R = 28.0;
  9. const double b = 8.0 / 3.0;
  10.  
  11. //[ system_function_without_perturbations
  12. struct lorenz
  13. {
  14. template< class State , class Deriv >
  15. void operator()( const State &x_ , Deriv &dxdt_ , double t ) const
  16. {
  17. typename boost::range_iterator< const State >::type x = boost::begin( x_ );
  18. typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
  19.  
  20. dxdt[0] = sigma * ( x[1] - x[0] );
  21. dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
  22. dxdt[2] = -b * x[2] + x[0] * x[1];
  23. }
  24. };
  25. //]
  26.  
  27.  
  28.  
  29. //[ system_function_with_perturbations
  30. const size_t n = 3;
  31. const size_t num_of_lyap = 3;
  32. const size_t N = n + n*num_of_lyap;
  33.  
  34. typedef boost::array< double , N > state_type;
  35. typedef boost::array< double , num_of_lyap > lyap_type;
  36.  
  37. void lorenz_with_lyap( const state_type &x , state_type &dxdt , double t )
  38. {
  39. lorenz()( x , dxdt , t );
  40.  
  41. for( size_t l=0 ; l<num_of_lyap ; ++l )
  42. {
  43. const double *pert = x.begin() + 3 + l * 3;
  44. double *dpert = dxdt.begin() + 3 + l * 3;
  45. dpert[0] = - sigma * pert[0] + 10.0 * pert[1];
  46. dpert[1] = ( R - x[2] ) * pert[0] - pert[1] - x[0] * pert[2];
  47. dpert[2] = x[1] * pert[0] + x[0] * pert[1] - b * pert[2];
  48. }
  49. }
  50. //]
  51.  
  52.  
  53.  
  54.  
  55.  
  56. int main( int argc , char **argv )
  57. {
  58. state_type x;
  59. lyap_type lyap;
  60. runge_kutta4< state_type > rk4;
  61.  
  62. fill( x.begin() , x.end() , 0.0 );
  63. x[0] = 10.0 ; x[1] = 10.0 ; x[2] = 5.0;
  64.  
  65. const double dt = 0.01;
  66.  
  67. //[ integrate_transients_with_range
  68. // perform 10000 transient steps
  69. integrate_n_steps( rk4 , lorenz() , std::make_pair( x.begin() , x.begin() + n ) , 0.0 , dt , 10000 );
  70. //]
  71.  
  72. //[ lyapunov_full_code
  73. fill( x.begin()+n , x.end() , 0.0 );
  74. for( size_t i=0 ; i<num_of_lyap ; ++i ) x[n+n*i+i] = 1.0;
  75. fill( lyap.begin() , lyap.end() , 0.0 );
  76.  
  77. double t = 0.0;
  78. size_t count = 0;
  79. while( true )
  80. {
  81.  
  82. t = integrate_n_steps( rk4 , lorenz_with_lyap , x , t , dt , 100 );
  83. gram_schmidt< num_of_lyap >( x , lyap , n );
  84. ++count;
  85.  
  86. if( !(count % 100000) )
  87. {
  88. cout << t;
  89. for( size_t i=0 ; i<num_of_lyap ; ++i ) cout << "\t" << lyap[i] / t ;
  90. cout << endl;
  91. }
  92. }
  93. //]
  94.  
  95. return 0;
  96. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:17: error: ‘boost’ has not been declared
 using namespace boost::numeric::odeint;
                 ^
prog.cpp:4:33: error: ‘odeint’ is not a namespace-name
 using namespace boost::numeric::odeint;
                                 ^
prog.cpp:4:39: error: expected namespace-name before ‘;’ token
 using namespace boost::numeric::odeint;
                                       ^
prog.cpp: In member function ‘void lorenz::operator()(const State&, Deriv&, double) const’:
prog.cpp:17:18: error: ‘boost’ has not been declared
         typename boost::range_iterator< const State >::type x = boost::begin( x_ );
                  ^
prog.cpp:17:39: error: expected ‘(’ before ‘<’ token
         typename boost::range_iterator< const State >::type x = boost::begin( x_ );
                                       ^
prog.cpp:17:41: error: expected primary-expression before ‘const’
         typename boost::range_iterator< const State >::type x = boost::begin( x_ );
                                         ^
prog.cpp:17:41: error: expected ‘;’ before ‘const’
prog.cpp:18:18: error: ‘boost’ has not been declared
         typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
                  ^
prog.cpp:18:39: error: expected ‘(’ before ‘<’ token
         typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
                                       ^
prog.cpp:18:47: error: expected primary-expression before ‘>’ token
         typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
                                               ^
prog.cpp:18:48: error: ‘::type’ has not been declared
         typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
                                                ^
prog.cpp:18:55: error: expected ‘;’ before ‘dxdt’
         typename boost::range_iterator< Deriv >::type dxdt = boost::begin( dxdt_ );
                                                       ^
prog.cpp:20:9: error: ‘dxdt’ was not declared in this scope
         dxdt[0] = sigma * ( x[1] - x[0] );
         ^
prog.cpp:20:29: error: ‘x’ was not declared in this scope
         dxdt[0] = sigma * ( x[1] - x[0] );
                             ^
prog.cpp: At global scope:
prog.cpp:34:9: error: ‘boost’ does not name a type
 typedef boost::array< double , N > state_type;
         ^
prog.cpp:35:9: error: ‘boost’ does not name a type
 typedef boost::array< double , num_of_lyap > lyap_type;
         ^
prog.cpp:37:30: error: ‘state_type’ does not name a type
 void lorenz_with_lyap( const state_type &x , state_type &dxdt , double t )
                              ^
prog.cpp:37:42: error: ISO C++ forbids declaration of ‘x’ with no type [-fpermissive]
 void lorenz_with_lyap( const state_type &x , state_type &dxdt , double t )
                                          ^
prog.cpp:37:46: error: ‘state_type’ has not been declared
 void lorenz_with_lyap( const state_type &x , state_type &dxdt , double t )
                                              ^
prog.cpp: In function ‘void lorenz_with_lyap(const int&, int&, double)’:
prog.cpp:43:32: error: request for member ‘begin’ in ‘x’, which is of non-class type ‘const int’
         const double *pert = x.begin() + 3 + l * 3;
                                ^
prog.cpp:44:30: error: request for member ‘begin’ in ‘dxdt’, which is of non-class type ‘int’
         double *dpert = dxdt.begin() + 3 + l * 3;
                              ^
prog.cpp:46:29: error: invalid types ‘const int[int]’ for array subscript
         dpert[1] = ( R - x[2] ) * pert[0] - pert[1] - x[0] * pert[2];
                             ^
prog.cpp:46:58: error: invalid types ‘const int[int]’ for array subscript
         dpert[1] = ( R - x[2] ) * pert[0] - pert[1] - x[0] * pert[2];
                                                          ^
prog.cpp:47:23: error: invalid types ‘const int[int]’ for array subscript
         dpert[2] = x[1] * pert[0] + x[0] * pert[1] - b * pert[2];
                       ^
prog.cpp:47:40: error: invalid types ‘const int[int]’ for array subscript
         dpert[2] = x[1] * pert[0] + x[0] * pert[1] - b * pert[2];
                                        ^
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:58:5: error: ‘state_type’ was not declared in this scope
     state_type x;
     ^
prog.cpp:58:16: error: expected ‘;’ before ‘x’
     state_type x;
                ^
prog.cpp:59:5: error: ‘lyap_type’ was not declared in this scope
     lyap_type lyap;
     ^
prog.cpp:59:15: error: expected ‘;’ before ‘lyap’
     lyap_type lyap;
               ^
prog.cpp:60:5: error: ‘runge_kutta4’ was not declared in this scope
     runge_kutta4< state_type > rk4;
     ^
prog.cpp:60:32: error: ‘rk4’ was not declared in this scope
     runge_kutta4< state_type > rk4;
                                ^
prog.cpp:62:11: error: ‘x’ was not declared in this scope
     fill( x.begin() , x.end() , 0.0 );
           ^
prog.cpp:69:104: error: ‘integrate_n_steps’ was not declared in this scope
     integrate_n_steps( rk4 , lorenz() , std::make_pair( x.begin() , x.begin() + n ) , 0.0 , dt , 10000 );
                                                                                                        ^
prog.cpp:75:11: error: ‘lyap’ was not declared in this scope
     fill( lyap.begin() , lyap.end() , 0.0 );
           ^
prog.cpp:83:9: error: ‘gram_schmidt’ was not declared in this scope
         gram_schmidt< num_of_lyap >( x , lyap , n );
         ^
stdout
Standard output is empty