Jump to content
  • Advertisement
Sign in to follow this  

Leapfrog Integrator's Only Half Right

This topic is 4261 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 using a leapfrog integrator in my physics engine, but the thing is though is that the only way it can have correct values that nearly match my results with all the other integrators that I've been experimenting with is by multiplying the positions and velocitys by 2. Here is an example code that I've used, only this is a for loop that displays 100 of the results:
    Dim t As Single, x As Single, v As Single, dt As Single, a As Single
    Dim i As Long
    
    t = 0
    x = 0
    v = 0
    a = 9.8
    dt = 1 / 100

    
    List1.AddItem "t" & "    " & "x" & "    " & "v"
    
    For i = 0 To 99
    
        x = x + v * dt
        v = v + a * dt
        v = v + -0.5 * a * dt
        t = t + dt
        
        'incorrect values:
        'List1.AddItem t & "    " & (x) & "    " & (v)   

        'correct values:
        List1.AddItem t & "    " & (x * 2) & "    " & (v * 2)
        
    Next i


Is the formula correct or did I do something wrong to get the results?

Share this post


Link to post
Share on other sites
Advertisement
Cause if its positive, the values are totally wrong. I got the code from this anyways, and he used -0.5 as well:

http://einstein.drexel.edu/courses/Comp_Phys/Integrators/leapfrog/simple_leapfrog.c

But the thing is though is that he used X for his dxdv's and deriv's functions when it was suppose to be V. Noticed that right away after taking a look at his Forward Euler integrator and RK4. And on top of that, it was only half way there with the leap frog, so I had to multiply the results by 2.

Share this post


Link to post
Share on other sites
x = x + v * dt
v = v + a * dt
v = v + -0.5 * a * dt
t = t + dt
...
v = v + a * dt + -0.5 * a * dt
...
v = v + 0.5 * a * dt

dt = 1
a = 4

0 + 0
0 + 4
4 - 2
...
0 + 2
2 + 4
6 - 2


SGD integrator

v = v0 + a*T
d = d0 + v*T

0 + 4
0 + 4
...
4 + 4
8 + 4 // note d0 = 4

real solution

d = v0*T + a*T^2 /2
v = a*T

d = 8



It seems you have a problem.

BTW One of leaprfrogs algorithms isn't required to use velocity explicitly. If you need to get velocity from velocityless integrator, you must recalculate it yourself.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!