11 #include <boost/program_options.hpp>
13 #include <utl/RK4ODEIntegrator.h>
14 #include <utl/RK5ODEIntegrator.h>
19 namespace po = boost::program_options;
24 main(
int argc,
char* argv[])
30 po::options_description desc(
"Allowed options");
32 (
"help,h",
"produce help message")
33 (
"dx,d", po::value<double>(&dx)->default_value(0.5),
"step size")
34 (
"x1,1", po::value<double>(&x1)->default_value(1000),
"end point")
35 (
"accuracy,a", po::value<double>(&accuracy)->default_value(1e-3),
36 "variable step accuracy")
37 (
"variable,v",
"run variable step")
38 (
"fixed,f",
"run variable step with fixed try")
42 po::store(po::parse_command_line(argc, argv, desc), vm);
45 if (vm.count(
"help")) {
55 const double omega =
sqrt(k / m);
60 const Vector y0 = { 1, 0 };
62 cout << setprecision(16);
64 if (!vm.count(
"variable")) {
71 for ( ; it4.
GetX() <= x1; it4 += dx, it5 += dx) {
72 const double x = it4.
GetX();
73 cout << x <<
' ' << it5.GetX() <<
' '
74 << it4.
GetY()[0] <<
' ' << it5.
GetY()[0] <<
' '
75 << it4.
GetY()[1] <<
' ' << it5.
GetY()[1] <<
' '
76 << y0[0] * cos(omega * x) <<
' '
77 << -y0[0] * sin(omega * x) <<
'\n';
85 const bool fixed = vm.count(
"fixed");
91 << it.
GetY()[0] <<
' '
92 << it.
GetY()[1] <<
' '
93 << y0[0] * cos(omega * x) <<
' '
94 << -y0[0] * sin(omega * x) <<
' ';
99 const double newx = it.
GetX();
100 cout << newx - x <<
'\n';
RK5Iterator< DerivativeFunctor, VectorType > Begin(const double x, const VectorType &y)
RK4Iterator< DerivativeFunctor, VectorType > Begin(const double x, const VectorType &y)
int main(int argc, char *argv[])
AdaptiveRK5Iterator< DerivativeFunctor, VectorType > AdaptiveBegin(const double x, const double dx, const VectorType &y, const double accuracy=1e-5)
double GetY(const CoordinateSystemPtr &coordinateSystem) const