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

Numerical Integration and Energy Loss

  1. Jul 21, 2008 #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 dependant 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 lets 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!


    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.

    Attached Files:

  2. jcsd
  3. Jul 21, 2008 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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 text books on Numerical Analysis search Amazon and get one.
  4. Jul 21, 2008 #3

    D H

    Staff: Mentor

    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.
  5. Jul 22, 2008 #4
    I can see I have a lot to learn... Thanks for the responses. Can you recommend a text book? I was looking at this one:

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


Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Numerical Integration and Energy Loss
  1. Numerical integration (Replies: 7)

  2. Numerical integration (Replies: 2)