pBook‎ > ‎Solver:: Integrator:: C++‎ > ‎

### Example Kin Sim

posted Dec 1, 2014, 10:08 PM by Javad Taghia   [ updated Dec 2, 2014, 8:26 PM ]
 //============================================================================//============================================================================#include #include #include #include #include #include typedef std::vector state_type;const double len = 1.7;// the rhs of x' = f(x)void harmonic_oscillator(const state_type &x, state_type &dxdt, const double t) { dxdt[0] =  x[3] * cos(x[2]); dxdt[1] =  x[3] * sin(x[2]); dxdt[2] = x[3] / len * tan(x[4]); dxdt[3] = 0; dxdt[4] = 0; }template std::vector createRange(vectype start, vectype end, vectype step ){    std::vector result;    for (; start < end; start += step) {        result.push_back(start);    }    return result;}int main() { state_type x(5); x[0] = 0.0; // xt x[1] = 0.0; // yt x[2] = 0.0; // tHeta x[3] = 1; // vf x[4] = 0; // dElta_t std::vector t = createRange(0, 10, 0.01); //for (double i=0; i<=10; i+=0.1) //t.push_back(i); std::cout << x[0] << "  " << x[1] << "  " << x[2] << std::endl; double t_old = 0; for (auto i: t) { size_t steps = boost::numeric::odeint:: integrate(harmonic_oscillator, x, t_old, i, 0.001); t_old = i; std::cout << x[0] << "  " << x[1] << "  " << x[2] << std::endl; } return 0;}with array#include #include #include typedef  boost::array state_type;const double len = 1.7;int main() { ashacontrol::stateModel model(len); state_type x; x[0] = 0.0; // xt x[1] = 0.0; // yt x[2] = 0.0; // tHeta x[3] = 1; // vf x[4] = 0; // dElta_t std::vector t = ashacontrol::createRange(0, 10, 0.01); std::cout << x[0] << "  " << x[1] << "  " << x[2] << std::endl; double t_old = 0; for (auto i: t) { size_t steps = boost::numeric::odeint:: integrate(model, x, t_old, i, 0.001); t_old = i; std::cout << x[0] << "  " << x[1] << "  " << x[2] << std::endl; }   getchar(); ashacontrol::CStopwatch timer1; splab::Timing splabtimer2; timer1.start(); splabtimer2.start(); std::string line; boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" ); while (std::cin) { `std::cout<<"hi"<
ą
12.png
(19k)