Question

I'm running g++ 4.7 on Mint 12 with boost 1.55. I'm trying to solve a simple 2d system of ode with odeint -- following the 1d example here: 1d. The 1d example compiles alright in both the original version and the amended version from the answer. Now, if I want a 2d system and I use double[2] things do not work:

#include <iostream>
#include <boost/numeric/odeint.hpp>

using namespace std;
using namespace boost::numeric::odeint;

void rhs( const double *x, double *dxdt, const double t )
{
    dxdt[0] = 3.0/(2.0*t*t) + x[0]/(2.0*t);
    dxdt[1] = 3.0/(2.0*t*t) + x[1]/(2.0*t);
}

void write_cout( double *x, const double t )
{
    cout << t << '\t' << x[0] << '\t' << 2*x[1] << endl;
}

typedef runge_kutta_cash_karp54< double[2] > stepper_type;

int main()
{
    double x[2] = {0.0,0.0};
    integrate_adaptive( make_controlled( 1E-12, 1E-12, stepper_type() ), rhs, x, 1.0, 10.0, 0.1, write_cout );
}

The error message is a mess, but ends with:

/usr/include/boost/numeric/odeint/algebra/range_algebra.hpp:129:47: error: function returning an array

Is the array double[2] the problem? And how should I fix it? Perhaps using a vector? By the way, I tried using both

typedef runge_kutta_cash_karp54< double > stepper_type;

typedef runge_kutta_cash_karp54< double , double , double , double , vector_space_algebra > stepper_type;

as suggested in the 1d answer, but to no avail. I should mention also that on an older machine with older boost (don't remember which version) everything compiled without problems. Thanks for any suggestion!

Was it helpful?

Solution

Use std::array< double ,2 >

#include <array>

typedef std::array< double , 2 > state_type;
void rhs( state_type const &x, state_type &dxdt, const double t )
{
    dxdt[0] = 3.0/(2.0*t*t) + x[0]/(2.0*t);
    dxdt[1] = 3.0/(2.0*t*t) + x[1]/(2.0*t);
}

void write_cout( state_type const& x, const double t )
{
    cout << t << '\t' << x[0] << '\t' << 2*x[1] << endl;
}

typedef runge_kutta_cash_karp54< state_type > stepper_type;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top