diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/numeric/odeint/examples/simple1d.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/numeric/odeint/examples/simple1d.cpp')
-rw-r--r-- | src/boost/libs/numeric/odeint/examples/simple1d.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/boost/libs/numeric/odeint/examples/simple1d.cpp b/src/boost/libs/numeric/odeint/examples/simple1d.cpp new file mode 100644 index 00000000..3a8dfa04 --- /dev/null +++ b/src/boost/libs/numeric/odeint/examples/simple1d.cpp @@ -0,0 +1,44 @@ +/* Boost libs/numeric/odeint/examples/simple1d.cpp + + Copyright 2012-2013 Mario Mulansky + Copyright 2012 Karsten Ahnert + + example for a simple one-dimensional 1st order ODE + + Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt) + */ + + +#include <iostream> +#include <boost/numeric/odeint.hpp> + +using namespace std; +using namespace boost::numeric::odeint; + + +/* we solve the simple ODE x' = 3/(2t^2) + x/(2t) + * with initial condition x(1) = 0. + * Analytic solution is x(t) = sqrt(t) - 1/t + */ + +void rhs( const double x , double &dxdt , const double t ) +{ + dxdt = 3.0/(2.0*t*t) + x/(2.0*t); +} + +void write_cout( const double &x , const double t ) +{ + cout << t << '\t' << x << endl; +} + +// state_type = double +typedef runge_kutta_dopri5< double > stepper_type; + +int main() +{ + double x = 0.0; //initial value x(1) = 0 + // use dopri5 with stepsize control and allowed errors 10^-12, integrate t=1...10 + integrate_adaptive( make_controlled( 1E-12 , 1E-12 , stepper_type() ) , rhs , x , 1.0 , 10.0 , 0.1 , write_cout ); +} |