Sign in to follow this  

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

This topic is 4354 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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
(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?

Share this post


Link to post
Share on other sites
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,

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4354 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this