# Runge-Kutta 4th Order

This topic is 4761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to do a particle simulation and I think my Runge-Kutta algorithm is working but I'm not sure if it is completely correct. The error may also be when I calculate the force but I think its in here. Am I doing it incorrectly? f=acceleration...
   // Runge-Kutta - 4th order
void RungeKutta()
{
// The stepsize
const double h = 0.005;

Vecd k1v = h * gVelocities;
Vecd k1f = h * SumForces(gPositions, gVelocities);

Vecd k2v = h * (gVelocities + k1f/2.0);
Vecd k2f = h * SumForces(gPositions + k1v/2.0, gVelocities + k1f/2.0);

Vecd k3v = h * (gVelocities + k2f/2.0);
Vecd k3f = h * SumForces(gPositions + k2v/2.0, gVelocities + k2f/2.0);

Vecd k4v = h * (gVelocities + k3f);
Vecd k4f = h * SumForces(gPositions + k3v, gVelocities + k3f);

gVelocities += k1f/6 + k2f/3 + k3f/3 + k4f/6;
gPositions  += k1v/6 + k2v/3 + k3v/3 + k4v/6;
}



##### Share on other sites
A useful way to check an integrator is to apply it to a problem where you already know the answer. Then you can compare the numerical result to the analytic result to make sure the integrator is behaving as you expect.

##### Share on other sites
Looks fine to me.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013715
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!