Eulers method....do i have to use 0.5 for the first calculation of velocity?

Started by
8 comments, last by rever 18 years, 3 months ago
Hello. I was looking at eulers implementation and i see that i have a 0.5 the first time i calculate the velocit, and this is becuase i am taking the average velocity between the initial time and time+timestep, and i need to use 0.5 for the first time i calculate the velocity. Is that correct?If not why do i need a 0.5 to calculate the velocity first time? Thx
Advertisement
i have no clue what you are getting at. why would the first time you compute velocity be any different from the other timesteps?

some code would help to illustrate i guess.
(dLastVelocity+dAcceleration*0.5*dTime)->First time calculation
(dLastVelocity+dAcceleration*dTime)-> All other times.
I am pretty sure this is correct as i found this in a binder from a physics class....
Why do i need a 0.5 for the first calculation?
it hardly seems vital to the simulation.

my guess is that its some kind of ad-hoc method to counter the derivation from a perfectly cicular orbit introduced by the error of euler integration,
actually that was for a general case that had nothing to do with circular orbits but rather motion of an objecet when thrown up.
Quote:Original post by rever
actually that was for a general case that had nothing to do with circular orbits but rather motion of an objecet when thrown up.


ah, i think i can explain it then.

even with constant acceleration, 1st order euler isnt completely accurate.

if you first update your velocity to get the velocity at the end of the timestep, then update your position with the velocity as it is at the end of the timestep, you are underestimating the displacement, as the velocity is lowest at the end of the timestep.

by appying the first step only half, the velocity is now not calculated at the end of each step, but rather at the midpoints of each timestep. so when you do pos = pos + vel * t, this is actualy an exact integration, since a is constant and thus v varies linearly, so the integral of v over t is v at the middle of the interval multiplied by t.
so this should increase the precision by some small and prolly insignificant degree on the gravity simulation?
simply using a 2nd order accurate integrator would probably be less confusing though. and keep in mind: this is only a hack that works for this specific situation: it doesnt make 1st order euler 2nd order accurate for the general case.
Quote:Original post by rever
so this should increase the precision by some small and prolly insignificant degree on the gravity simulation?


i dont know if the influence on the gravity simulator will be a positive one at all.
thx alot for that:D

This topic is closed to new replies.

Advertisement