]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/odeint/examples/multiprecision/cmp_precision.cpp
1 /* Boost libs/numeric/odeint/examples/multiprecision/cmp_precision.cpp
3 Copyright 2013 Karsten Ahnert
4 Copyright 2013 Mario Mulansky
6 example comparing double to multiprecision using Boost.Multiprecision
8 Distributed under the Boost Software License, Version 1.0.
9 (See accompanying file LICENSE_1_0.txt or
10 copy at http://www.boost.org/LICENSE_1_0.txt)
15 #include <boost/numeric/odeint.hpp>
16 #include <boost/multiprecision/cpp_dec_float.hpp>
19 using namespace boost::numeric::odeint
;
21 typedef boost::multiprecision::cpp_dec_float_50 mp_50
;
23 /* we solve the simple ODE x' = 3/(2t^2) + x/(2t)
24 * with initial condition x(1) = 0.
25 * Analytic solution is x(t) = sqrt(t) - 1/t
28 void rhs_m( const mp_50 x
, mp_50
&dxdt
, const mp_50 t
)
29 { // version for multiprecision
30 dxdt
= mp_50(3)/(mp_50(2)*t
*t
) + x
/(mp_50(2)*t
);
33 void rhs_d( const double x
, double &dxdt
, const double t
)
34 { // version for double precision
35 dxdt
= 3.0/(2.0*t
*t
) + x
/(2.0*t
);
38 // state_type = mp_50 = deriv_type = time_type = mp_50
39 typedef runge_kutta4
< mp_50
, mp_50
, mp_50
, mp_50
, vector_space_algebra
, default_operations
, never_resizer
> stepper_type_m
;
41 typedef runge_kutta4
< double , double , double , double , vector_space_algebra
, default_operations
, never_resizer
> stepper_type_d
;
46 stepper_type_m stepper_m
;
47 stepper_type_d stepper_d
;
52 cout
<< "dt" << '\t' << "mp" << '\t' << "double" << endl
;
57 mp_50 x_m
= 0; //initial value x(1) = 0
58 stepper_m
.do_step( rhs_m
, x_m
, mp_50( 1 ) , dt_m
);
60 stepper_d
.do_step( rhs_d
, x_d
, 1.0 , dt_d
);
63 cout
<< abs((x_m
- (sqrt(1+dt_m
)-mp_50(1)/(1+dt_m
)))/x_m
) << '\t' ;
64 cout
<< abs((x_d
- (sqrt(1+dt_d
)-mp_50(1)/(1+dt_d
)))/x_d
) << endl
;