Second-order differential equation using the C ++ Boost odeint library

Using the boost C ++ odeint library, is it possible to solve a second-order differential equation defined as follows:

m*x''[i] + x'[i] = K*\sum{j=1,N} sin(x[j] - x[i]), where i = 1,2,3..N.
m = 1, K = 1

where the initial value of x is a vector or an array of N uniformly generated random numbers from 0 to 2 * pi. I want to integrate the above equation with runge_kutta stepper odeint?

I can solve this by writing the above equation. in two differential equations of the first order, but then in this case, how will the odeint pedometer be written or modified?

+4
source share
1 answer

ODE 2 N. N x[i], N x'[i]

void ode( state_type const& x , state_type &dxdt , double t )
{
    for( size_t i=0 ; i<N ; ++i )
    {
        double sum = 0.0;
        // calculate sum
        dxdt[i] = x[i+N];
        dxdt[i+N] = K * sum;
    }
}

size_t N = 512;
typedef std::vector< double > state_type;
state_type x( 2 * N );
// initialize x
double t_start = 0.0 , t_end = 10.0 , dt = 0.01;
odeint::integrate( ode , x , t_start , t_end , dt );
+4

Source: https://habr.com/ru/post/1525039/


All Articles