lorenz_gmpxx.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * lorenz_gmpxx.cpp
  3. *
  4. * This example demonstrates how odeint can be used with arbitrary precision types.
  5. *
  6. * Copyright 2011-2012 Karsten Ahnert
  7. * Copyright 2011-2012 Mario Mulansky
  8. *
  9. * Distributed under the Boost Software License, Version 1.0.
  10. * (See accompanying file LICENSE_1_0.txt or
  11. * copy at http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. #include <iostream>
  14. #include <boost/array.hpp>
  15. #include <gmpxx.h>
  16. #include <boost/numeric/odeint.hpp>
  17. using namespace std;
  18. using namespace boost::numeric::odeint;
  19. //[ gmpxx_lorenz
  20. typedef mpf_class value_type;
  21. typedef boost::array< value_type , 3 > state_type;
  22. struct lorenz
  23. {
  24. void operator()( const state_type &x , state_type &dxdt , value_type t ) const
  25. {
  26. const value_type sigma( 10.0 );
  27. const value_type R( 28.0 );
  28. const value_type b( value_type( 8.0 ) / value_type( 3.0 ) );
  29. dxdt[0] = sigma * ( x[1] - x[0] );
  30. dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
  31. dxdt[2] = -b * x[2] + x[0] * x[1];
  32. }
  33. };
  34. //]
  35. struct streaming_observer
  36. {
  37. std::ostream& m_out;
  38. streaming_observer( std::ostream &out ) : m_out( out ) { }
  39. template< class State , class Time >
  40. void operator()( const State &x , Time t ) const
  41. {
  42. m_out << t;
  43. for( size_t i=0 ; i<x.size() ; ++i ) m_out << "\t" << x[i] ;
  44. m_out << "\n";
  45. }
  46. };
  47. int main( int argc , char **argv )
  48. {
  49. //[ gmpxx_integration
  50. const int precision = 1024;
  51. mpf_set_default_prec( precision );
  52. state_type x = {{ value_type( 10.0 ) , value_type( 10.0 ) , value_type( 10.0 ) }};
  53. cout.precision( 1000 );
  54. integrate_const( runge_kutta4< state_type , value_type >() ,
  55. lorenz() , x , value_type( 0.0 ) , value_type( 10.0 ) , value_type( value_type( 1.0 ) / value_type( 10.0 ) ) ,
  56. streaming_observer( cout ) );
  57. //]
  58. return 0;
  59. }