-2

I want to model the motion of a particle using a set of 2nd order equations the the equation is

d2x/dt2 = 1 + dy/dt + dz/dt 
d2y/dt2 = 1 + dx/dt + dz/dt 
d2z/dt2 = 1 + dx/dt + dy/dt

vector V is (dx/dt dy/dt dz/dt), X is (x y z), V = [0 0 0], X = [0 0 0] initially

I implemented this into C code for one of the ODEs below CODE;

double X_function(double a[], double t, double at[],double b[],double c[]) {
//double yt, zt;
at[0] = a[0];
at[1] = 1 + b[0] + c[0];
double F = at[1];
return F;
}

i need help understanding how to use R-K in such a case

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51

1 Answers1

1

You have an equation

x''=F(x,x')

that you rewrite as an first order system

x' = v
v' = F(x,v)

Implement this coupled 6-dimensional system as one function

void derivs(double u[], double t, double du[]) {
    int j,k;
    for(k=0; k<3; k++) {
        du[k] = u[3+k];
        du[3+k] = 1;
        for(j=0;j<3; j++) 
            if(j!=k) du[3+k] += u[j]
    }
}

then you can implement the Runge-Kutta method in a general form for a first-order system.

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51