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

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

## 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 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 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 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 on other sites
actually that was for a general case that had nothing to do with circular orbits but rather motion of an objecet when thrown up.

##### Share on other sites
Quote:
 Original post by reveractually 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 on other sites
so this should increase the precision by some small and prolly insignificant degree on the gravity simulation?

##### 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 on other sites
Quote:
 Original post by reverso 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 on other sites
thx alot for that:D

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633269
• Total Posts
3011153
• ### Who's Online (See full list)

There are no registered users currently online

×