\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
xam_an_ode.cpp¶
View page sourceExample and Test of an_ode¶
# include <ctime>
# include <cmpad/algo/an_ode.hpp>
# include <cmpad/near_equal.hpp>
# include <limits>
bool xam_an_ode(void)
{ //
// ok
bool ok = true;
//
// n
size_t n = 4;
//
// ode
typedef cmpad::vector<double> Vector;
cmpad::an_ode<Vector> ode;
//
// ode.setup
cmpad::option_t option;
option.n_arg = n;
option.n_other = n-1;
ode.setup(option);
//
// x
Vector x = { 1.0, 2.0, 3.0, 4.0 };
ok &= x.size() == n;
//
// yf
Vector yf = ode(x);
//
// rel_error
double rel_error = std::numeric_limits<double>::epsilon() * 100.0;
//
// ok
double tf = 2.0;
double yi = x[0] * tf;
ok &= cmpad::near_equal( yf[0], yi, rel_error );
for(size_t i = 1; i < n; ++i)
{ yi = x[i] * yi * tf / double(i+1);
ok &= cmpad::near_equal( yf[i], yi, rel_error );
}
//
return ok;
}