Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!