Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Results same w/ Euler, Improved Euler, & Runge-Kutta

  1. Feb 4, 2007 #1
    I've been trying to do some simulations using the Euler, improved Euler, and Runge-Kutta methods. My results for the improved Euler and Runge-Kutta are very close to my results with the plain old Euler method. If there is any improvement, it is negligible. This lack of improvement surprises me. Is it a common occurrence? Is it likely that I have a round off error somewhere?
     
  2. jcsd
  3. Feb 4, 2007 #2

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    You should be able to take larger time steps with the RK and maintain accuracy. A lot depends on the DE you are solving. If the solution is smooth and slowly changing then it does not matter much what method you choose. If there are rapid changes (say a step function involved in the boundary or initial conditions) then you will see a difference.

    The standard Euler method loses even a simple pendulum pretty quickly, the improved Euler and RK does much better.
     
  4. Feb 6, 2007 #3
    I'm doing a mass spring. The equation for acceleration

    a = -kx -bv

    seems to keep things in bounds. I have, however, been having some phase problems.
     
  5. Feb 7, 2007 #4

    arildno

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    Dearly Missed

    This is not surprising. In pendulum problems, it is generally true that phase inaccuracies (period mismatching) will occur earlier than amplitude inaccuracies.
     
  6. Feb 7, 2007 #5
    Are there other numerical methods, perhaps more obscure ones, that specifically address the issue of phase?
     
  7. Feb 7, 2007 #6

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Go with RK4
     
  8. Feb 8, 2007 #7
    RK4 seems to keeps things in phase a little better than the Euler. In contrast, at higher frequencies the magnitude of the oscillations seem to be better represented by the Euler.
     
  9. Feb 8, 2007 #8

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Keep a VERY close eye on the Euler methods, I have seen it produce absolutly beautiful garbage. The forward step version is signifanlty more stable then the standard Euler.
     
  10. Feb 9, 2007 #9
    I had a fairly good improvement using the leap-frog method instead of the Euler. In contrast, I used the Verlet method and everthing seemed to be much worse than the Euler. I can't say if I'm doing the Verlet correctly, or if one should expect the Verlet method to be way off for a damped oscillator.

    Point taken. I'm using an "adaptive" leap-frog scheme, but I might be able to improve my frequency of oscillation. Perhaps I will try some sort of adaptive RK4.
     
  11. Feb 9, 2007 #10

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Just a couple of aside comments.

    If you take steps that are a power of 2 you will not be introducing round off errors. If you are not aware of it .1 (decimal) when translated to binary becomes the infinitely repeating fraction .00011001100.... So no mater how many digits you can carry, you MUST round off .1.

    To me this is a very good reason to AVOID taking a step size which is a power of 10.
     
  12. Feb 13, 2007 #11
    That's an interesting point. But what if my output data needs to have a step size that is a factor of 10? Should I use a factor of 2 that is smaller, and then interpolate?
     
  13. Feb 13, 2007 #12

    jim mcnamara

    User Avatar
    Science Advisor
    Gold Member

    Integral has it exactly.

    Floating point representations of numbers have issues. For example: in C, the float, double, and long double data types are FP's with increasing precision. As you extend precision you move the fuzz "further out", and it may sometimes defer the onset of your kind of issue to a later iteration. It does not get rid of it.

    If you're using C, consider long double data types and see if it buys you anything in terms of the timing of the onset of phase issues. It may not.
    I don't know what your goal is.

    You could also interpolate the final results and use a factor of 2. Or find a BCD library ($$) with the precision you need for your model.
     
  14. Feb 13, 2007 #13

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    If you feel you must take a power of 10 step use an integer counter to increment your steps then multiply by the step size. Do NOT add your power of 10 step to increment your process.

    I recall that on my old 8 bit AppleII that the code

    5 x= 0
    10 x = x + .1

    yielded .9999999 after 10 interations.

    but
    5 x = 0 : n =0 : st= .1
    10 for n = 1 to 10
    15 x = n*st
    20 next n

    gave correct results

    The first method accumulates the round off error, while the second does not.
     
  15. Feb 15, 2007 #14
    I'm not sure what you are doing in your code. The first one looks like a numerical method, but the second looks like you are preparing a vector, x, for a plot.

    A step size of 1 through my numbers way off. I tried setting the step size to
    and then multiplying my output array by 66536.0 and the real step size as follows
     
  16. Mar 8, 2007 #15
    I've now done a 4th order Runge-Kutta and a Euler-Cromer-Leap-Frog. The Euler-Cromer-Leap-Frog seems to win out on every test. I've long help the belief that Runge-Kuttas were better than Euleroid methods. My tests have shown this not to be the case. Am I missing something? Is there a such thing as some sort of Rung-Kutta-Leap-Frog?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Results same w/ Euler, Improved Euler, & Runge-Kutta
  1. Runge kutta (Replies: 4)

Loading...