Welcome, Guest

Author Topic: Math, euler vs rk4  (Read 4159 times)

Technotica

  • *
  • Posts: 9
Math, euler vs rk4
« on: May 03, 2011, 08:44:15 AM »
Hi!

I know RK4 is more accurate than euler but needs more computing power, what I am wondering is what the actual differences between the two are.

I don't mean the math itself but what would we have to do to see the bodies in a simulation behaving differently between euler and rk4? At what point does euler become so inaccurate that you notice it?

If I simulated the solar system and let it run for a few thousand years (in game time of course) would that system calculated with euler look totally different than with rk4? Or would only more drastic things change the result between the two methods? Lets say I install a second sun in the solar system would that make the bodies in the system behave radically different in euler than in rk4?


Thanks!

edit

I just thought about something else, since rk4 slows my computer down more than euler, if I accelerated time with both methods, lets say to 4 days time step and my fps are significantly lower with rk4 than with euler, would rk4 still be more accurate than euler?

Because it can't calculate as well when you have low fps right? The worse your fps the more inaccurate the projected paths become I think?
« Last Edit: May 03, 2011, 08:49:51 AM by Technotica »

Joshimitsu91

  • *****
  • Posts: 78
  • Hit me up on Steam: "Joshimitsu91"
Re: Math, euler vs rk4
« Reply #1 on: May 03, 2011, 09:35:48 AM »
I think that you would see a noticable difference with the Euler method, since i have studied them a little in my computational physics course. I couldn't tell you by how much though.

I just thought about something else, since rk4 slows my computer down more than euler, if I accelerated time with both methods, lets say to 4 days time step and my fps are significantly lower with rk4 than with euler, would rk4 still be more accurate than euler?

Because it can't calculate as well when you have low fps right? The worse your fps the more inaccurate the projected paths become I think?

I don't think your FPS matters since the "Time Step" you select means how much time for each frame of the simulation, so a lower FPS should just mean that time unfolds slower than a high FPS for a given time step. Although i may be wrong...

A good tip is to set your trails to auto-length to improve performance, it makes a huge difference on the solar system simulations!

EDIT:

I think my comment about the time step is correct, as i have just observed that the "real second" parameter varies according to FPS when you set the "Time Step". For example, my simulation was running at 200 FPS with a 15 minute time-step and 1 real second was equivalent to approximately 2 days. When the FPS dropped to about 175, the real second dropped to about 1.75 days.

Also, having a larger time step will cause your simulation to be less accurate, sometimes you will see mercury shoot off at insane speeds if you set the time step too high :P
« Last Edit: May 03, 2011, 09:41:16 AM by Joshimitsu91 »

Technotica

  • *
  • Posts: 9
Re: Math, euler vs rk4
« Reply #2 on: May 04, 2011, 12:30:18 AM »
Hmm, thnaks for the answer!

So it seems euler should only really be used if rk4 slows the simulation down so much its unwatchable :)

Euler doubles my framerate, so I was wondering if the inaccuracies aren't too bad, but I think I'lls tick to rk4 then :)

Joshimitsu91

  • *****
  • Posts: 78
  • Hit me up on Steam: "Joshimitsu91"
Re: Math, euler vs rk4
« Reply #3 on: May 04, 2011, 07:25:19 AM »
To be honest i think you'll still be able to make nice systems etc. using the euler method if it helps your performance, its only if you're bothered about that extra accuracy. I use the RK4 but thats purely because my PC can handle it, i've used the euler method too when i didnt realise it was selected.

Josh

Dan Dixon

  • Creator of Universe Sandbox
  • Developer
  • *****
  • Posts: 3244
    • Personal Site
Re: Math, euler vs rk4
« Reply #4 on: May 04, 2011, 01:05:19 PM »
The main easily observational difference is that when you have extremely elliptical orbits, they will unrealistically flatten out and become circular when using Euler (pronounced 'Oiler'), but won't if using RK4.

Here's a great article that talks about the difference between them:
http://gafferongames.com/game-physics/integration-basics/

Although I don't agree with his statement that if you use Euler then you're an idiot. That's simply not true. :)