stuart_landau.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * stuart_landau.cpp
  3. *
  4. * This example demonstrates how one can use odeint can be used with state types consisting of complex variables.
  5. *
  6. * Copyright 2011-2012 Karsten Ahnert
  7. * Copyright 2011-2013 Mario Mulansky
  8. * Distributed under the Boost Software License, Version 1.0. (See
  9. * accompanying file LICENSE_1_0.txt or copy at
  10. * http://www.boost.org/LICENSE_1_0.txt)
  11. */
  12. #include <iostream>
  13. #include <complex>
  14. #include <boost/array.hpp>
  15. #include <boost/numeric/odeint.hpp>
  16. using namespace std;
  17. using namespace boost::numeric::odeint;
  18. //[ stuart_landau_system_function
  19. typedef complex< double > state_type;
  20. struct stuart_landau
  21. {
  22. double m_eta;
  23. double m_alpha;
  24. stuart_landau( double eta = 1.0 , double alpha = 1.0 )
  25. : m_eta( eta ) , m_alpha( alpha ) { }
  26. void operator()( const state_type &x , state_type &dxdt , double t ) const
  27. {
  28. const complex< double > I( 0.0 , 1.0 );
  29. dxdt = ( 1.0 + m_eta * I ) * x - ( 1.0 + m_alpha * I ) * norm( x ) * x;
  30. }
  31. };
  32. //]
  33. /*
  34. //[ stuart_landau_system_function_alternative
  35. double eta = 1.0;
  36. double alpha = 1.0;
  37. void stuart_landau( const state_type &x , state_type &dxdt , double t )
  38. {
  39. const complex< double > I( 0.0 , 1.0 );
  40. dxdt = ( 1.0 + m_eta * I ) * x - ( 1.0 + m_alpha * I ) * norm( x ) * x;
  41. }
  42. //]
  43. */
  44. struct streaming_observer
  45. {
  46. std::ostream& m_out;
  47. streaming_observer( std::ostream &out ) : m_out( out ) { }
  48. template< class State >
  49. void operator()( const State &x , double t ) const
  50. {
  51. m_out << t;
  52. m_out << "\t" << x.real() << "\t" << x.imag() ;
  53. m_out << "\n";
  54. }
  55. };
  56. int main( int argc , char **argv )
  57. {
  58. //[ stuart_landau_integration
  59. state_type x = complex< double >( 1.0 , 0.0 );
  60. const double dt = 0.1;
  61. typedef runge_kutta4< state_type > stepper_type;
  62. integrate_const( stepper_type() , stuart_landau( 2.0 , 1.0 ) , x , 0.0 , 10.0 , dt , streaming_observer( cout ) );
  63. //]
  64. return 0;
  65. }