Numerical Integration and Energy Loss

Click For Summary
SUMMARY

This discussion focuses on the analysis of numerical integration methods for simulating a simple pendulum's motion, specifically using Forward Euler, Second Order Runge Kutta (RK2), Third Order Adams Bashforth (AB3), and Fourth Order Runge Kutta (RK4). The user observed that while all methods produced similar results at high frequencies, the AB3 method exhibited energy loss at lower frequencies, unlike RK4, which maintained energy. The conversation highlights the importance of understanding the characteristics of these methods, particularly their energy conservation properties, and suggests that none of the discussed methods are symplectic integrators, which typically conserve energy in conservative systems.

PREREQUISITES
  • Understanding of numerical integration methods, specifically Forward Euler, RK2, RK3 (AB3), and RK4.
  • Familiarity with energy conservation principles in physics simulations.
  • Basic knowledge of MATLAB for state derivative calculations.
  • Experience with C++ for simulation execution and integration method implementation.
NEXT STEPS
  • Research symplectic integrators and their applications in conservative systems.
  • Learn about error analysis in numerical methods to understand energy loss implications.
  • Explore advanced numerical analysis textbooks, such as the one recommended in the discussion.
  • Investigate methods to compensate for energy loss in numerical simulations.
USEFUL FOR

This discussion is beneficial for physicists, engineers, and developers involved in simulations, particularly those focusing on numerical integration methods and energy conservation in dynamic systems.

KLoux
Messages
174
Reaction score
1
Hello. I've recently been using a few different numerical integration methods to solve a number of different problems, and as I looked into the integration algorithms, I realized that I don't understand them as well as I thought I did. I created a simple Excel workbook that calculates the motion of a simple pendulum and performed the integration using four different methods: Forward Euler, Second Order Runge Kutta, Third Order Adams Bashforth, and Fourth Order Runge Kutta.

At first I looked only at plots of the pendulum's velocity and position, but all four methods had similar results. I had to look at a very small time scale before I could see the differences. I tried reducing the simulation frequency to see if the differences between the methods would become more obvious. When I dropped the frequency down to 20 Hz, I noticed that that the AB3 simulation was loosing energy. I added a plot to show the energy.

The RK4 method, not surprisingly, appeared to have no energy loss. The RK2 and Euler methods oscillated (Euler had amplitude ~30 times the amplitude of RK2 method) but appeared to maintain a constant average value (no long-term loss). The AB3 method started loosing energy right from the start of the simulation (see attached plot). This brings me to my first questions: Is this a characteristic of the AB methods? Is this something that is specific to this simulation? In another simulation would I be gaining energy?

Initially I thought that the energy loss was primarily dependent on simulation frequency, but I realized that I was simulating a fixed number of time steps rather than a fixed amount of time (a result of using Excel for the simulations). I though perhaps a plot of rate of energy loss would remove this effect. I was surprised to see that the rate of energy loss (of all of the methods) was inversely proportional to the simulation frequency. This makes sense for the methods whose energy oscillates, but I didn't expect it for the RK4 and AB3 methods. I also noticed that the RK4 method was also loosing energy. It was disappearing at a much lower rate (~10e-8 times AB3 - definitely negligible for my purposes) but the rate of change of energy for the method was always negative. So my second questions: Why? I would expect the RK2 and RK4 methods to have similar shapes for these curves, but this is does not appear to be the case. Does it sound like my implementation is flawed?

Most of my simulations run from a C++ application that calls MATLAB to calculate the state derivatives. I previously favored the AB3 method because I can store the state derivatives from previous time steps, and I only need to call MATLAB once every time step to calculate the next time step. This results in a much faster execution and let's me run the simulations at a higher frequency. I am sure that I would have to reduce my simulation frequency to switch to RK4, which would have to make four calls to MATLAB every time step, as I have a requirement to run faster than real-time (and MATLAB is very slow). And now my last questions: Is there a way that I can "add" energy back to the system if I know what my energy loss (due to the integration algorithm) was? Should I look into RK4 or something else that runs faster and will loose less energy? Is energy loss even a valid way to asses the accuracy of a simulation?

If you've read this far through the post, then thank you for your time (and I'm sorry it was so long!). Thanks for your help!

-Kerry

p.s. I was hoping to be able to post the spreadsheet, but the file was too large. If you're interested in seeing it I can remove some plots to make it smaller and try posting it here again, or I can e-mail it to you - just let me know.
 

Attachments

  • energy.JPG
    energy.JPG
    54.9 KB · Views: 880
Physics news on Phys.org
I have encountered others who refer to errors in numerical methods as "energy loss". I just see this as errors inherent to the methods. Remember that these are approximations, since you are approximating the same system you should be seeing similar results for each method. Further the errors of all of these methods are proportional to the step size. If you see more difference with smaller steps something is wrong. The differences should get smaller as the step is reduced.

You should find an error analysis as part of the derivation of these methods. There are many good textbooks on Numerical Analysis search Amazon and get one.
 
KLoux said:
The RK4 method, not surprisingly, appeared to have no energy loss. The RK2 and Euler methods oscillated (Euler had amplitude ~30 times the amplitude of RK2 method) but appeared to maintain a constant average value (no long-term loss). The AB3 method started loosing energy right from the start of the simulation (see attached plot).
I have implemented many numerical integrators, and my first and only reaction upon seeing an integrator that gives worse than forward Euler by any metric is "I made a mistake somewhere". I suspect you did the same here with your AB3 integrator.

None of the techniques you cited are symplectic integrators, which means they typically do not conserve energy when applied to a conservative problem.
 
Integral said:
You should find an error analysis as part of the derivation of these methods. There are many good textbooks on Numerical Analysis search Amazon and get one.

D H said:
None of the techniques you cited are symplectic integrators, which means they typically do not conserve energy when applied to a conservative problem.

I can see I have a lot to learn... Thanks for the responses. Can you recommend a textbook? I was looking at this one:
https://www.amazon.com/dp/0486652416/?tag=pfamazon01-20

Do you have any experience with it? It's cheap and seems to have gotten good reviews.

Thanks!

-Kerry
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 65 ·
3
Replies
65
Views
8K
  • · Replies 31 ·
2
Replies
31
Views
8K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K