Hi. I want to evolve those equations in time from zero to 10^16 and initial condotions x(0)=10^8 and y(0)= 0.5. Because of the dependence of the equations on x in the denominator I think using odeint with runge_kutta_dopri5 is a good choice because of the adaptive step control. The thing is I have little idea how to do this in practice cause i have little experience in c++ and odeint. I searched a lot about using odeint but the examples where not helpful for me. Also i want to stop the calculations when x reaches zero i saw this https://stackguides.com/questions/33334073/stop-integration-in-odeint-with-stiff-ode
based on examples i wrote this so far with no luck
#include <iostream>
#include <vector>
#include <cmath>
#include <boost/array.hpp>
#include <boost/numeric/odeint.hpp>
using namespace std;
using namespace boost::numeric::odeint;
const double b = 43.0e17;
typedef boost::array< double , 2 > state_type;
void binary(const state_type &x , state_type &dxdt , double t )
{
dxdt[0] = -b*(64.0/5)*(1 + (73.0/24)*pow(x[1],2)
+ 37.0/96)*pow(x[1],4) )/pow(x[0],3)*pow(1-pow(x[1],2),7.0/2);
dxdt[1] = -b*(304.0/96)*x[1]*(1 + (121.0/304)*pow(x[1],2))
/pow(x[0],4)*pow((1 - pow(x[1],2)),5.0/2);
}
void write_binary( const state_type &x , const double t )
{
cout << t << '\t' << x[0] << '\t' << x[1] << '\t' << x[2] << endl;
}
//I dont know what this does but the examples used it
struct streaming_observer
{
std::ostream& m_out;
streaming_observer( std::ostream &out ) : m_out( out ) { }
template< class State , class Time >
void operator()( const State &x , Time t ) const
{
m_out << t;
for( size_t i=0 ; i<x.size() ; ++i ) m_out << "\t" << x[i] ;
m_out << "\n";
}
};
//This was a first try with a given stepper but i want to replace it
int main(int argc, char **argv)
{
state_type x = { 20.871e8 , 0.5 }; // initial conditions
integrate( binary , x , 0.0 , 1000.0 , 0.1 , write_binary );
}
When I compiled it a run it I got this error
Internal Program Error - assertion (i < N) failed in const T& boost::array::operator[](boost::array::size_type) const [with T = double; long unsigned int N = 2ul; boost::array::const_reference = const double&; boost::array::size_type = long unsigned int]: /usr/include/boost/array.hpp(129): out of range Aborted (core dumped)
How can i get this work?
state_type x = { 20.871e8 , 0.5 };
. – CroCo