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

In summary, the results for improved Euler and Runge-Kutta methods are very similar to those of the standard Euler method. This lack of improvement may be due to the smooth and slowly changing nature of the solution being simulated. However, at higher frequencies, the Euler method may provide better representation of the magnitude of oscillations. In terms of phase accuracy, the RK4 method is slightly better than the Euler method. Additionally, taking steps that are a power of 2 can prevent round off errors. Using an adaptive leap-frog scheme or an adaptive RK4 method may improve frequency of oscillation. It is also important to consider the precision of floating point representations, such as using long double data types in C. However, if a power of
  • #1
dimensionless
462
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?
 
Physics news on Phys.org
  • #2
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.
 
  • #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.
 
  • #4
dimensionless said:
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.

This is not surprising. In pendulum problems, it is generally true that phase inaccuracies (period mismatching) will occur earlier than amplitude inaccuracies.
 
  • #5
Are there other numerical methods, perhaps more obscure ones, that specifically address the issue of phase?
 
  • #6
Go with RK4
 
  • #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.
 
  • #8
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.
 
  • #9
I had a fairly good improvement using the leap-frog method instead of the Euler. In contrast, I used the Verlet method and everything 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.

Integral said:
Keep a VERY close eye on the Euler methods, I have seen it produce absolutly beautiful garbage. The forward step version is significantly more stable then the standard Euler.

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.
 
  • #10
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.
 
  • #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?
 
  • #12
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.
 
  • #13
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.
 
  • #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
h = 1.0/65536.0;
and then multiplying my output array by 66536.0 and the real step size as follows
for(i=0; i<length; i++)
{

out_put = out_put*65536.0*step_size;

}
 
  • #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?
 

1. What is Euler's method and how does it compare to the improved Euler and Runge-Kutta methods?

Euler's method is a numerical method for solving ordinary differential equations. It involves taking small steps to approximate the solution. Improved Euler and Runge-Kutta methods are also numerical methods for solving ODEs, but they use more accurate calculations and smaller step sizes, resulting in more precise solutions.

2. How do I know which method to use for solving a differential equation?

The method you choose depends on the level of accuracy you need for your solution. If you need a rough estimate, Euler's method may be sufficient. If you need a more precise solution, improved Euler or Runge-Kutta methods would be better options.

3. Are there any limitations to using these numerical methods?

Yes, there are limitations to using these methods. They may not work for all types of differential equations, and they may not always provide accurate solutions. It is important to analyze the problem and consider the strengths and weaknesses of each method before choosing one.

4. Can these methods be used for solving systems of differential equations?

Yes, all three methods can be used for solving systems of differential equations. However, the process may become more complex and time-consuming as the number of equations increases.

5. How can I determine the accuracy of the solutions obtained from these methods?

The accuracy of the solutions obtained from these methods can be determined by comparing them to the exact solution, if available. Another way to evaluate accuracy is by using a smaller step size and comparing the results to the previous solution. The smaller the difference, the more accurate the solution.

Similar threads

Replies
9
Views
2K
  • Differential Equations
Replies
7
Views
2K
  • Differential Equations
Replies
1
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
  • Differential Equations
Replies
4
Views
3K
  • Differential Equations
Replies
4
Views
4K
  • Differential Equations
Replies
1
Views
4K
  • Astronomy and Astrophysics
Replies
22
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
Replies
2
Views
269
Back
Top