Numerical Integration and Energy Loss

In summary, the speaker discusses their experience using different numerical integration methods and their realization that they do not fully understand the algorithms. They created a simple Excel workbook to compare four different methods and noticed differences in energy loss, leading to questions about the accuracy and validity of the simulations. They also mention their use of MATLAB and the benefits of different integration methods. Ultimately, they seek recommendations for a textbook on numerical analysis to further their understanding.
  • #1
KLoux
176
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 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: 773
Physics news on Phys.org
  • #2
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.
 
  • #3
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.
 
  • #4
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
 

1. What is numerical integration?

Numerical integration is a method used to approximate the value of a definite integral of a function. It involves dividing the area under the curve into smaller sub-intervals and using a numerical algorithm to calculate the sum of these sub-intervals.

2. How is numerical integration used in science?

Numerical integration is used in many scientific fields, such as physics, engineering, and economics, to calculate the value of integrals that cannot be solved analytically. It is also used to model and simulate complex systems and phenomena that involve continuous changes over time.

3. What factors affect the accuracy of numerical integration?

The accuracy of numerical integration depends on several factors, including the number of sub-intervals used, the choice of numerical algorithm, and the smoothness of the function being integrated. The smaller the sub-intervals and the more precise the algorithm, the more accurate the result will be.

4. What is energy loss and how is it related to numerical integration?

Energy loss is the decrease in the total energy of a system over time due to various factors such as friction, resistance, and other dissipative forces. Numerical integration is used to calculate the amount of energy lost in a system by integrating the power (rate of energy transfer) over time.

5. Can numerical integration be used to solve real-world problems?

Yes, numerical integration is used extensively in real-world applications to solve a wide range of problems. For example, it is used in physics to calculate the trajectories of objects under the influence of gravity, in engineering to design structures and simulate fluid flow, and in economics to model financial systems and predict market trends.

Similar threads

  • Differential Equations
Replies
1
Views
1K
  • Differential Equations
Replies
1
Views
1K
Replies
9
Views
2K
  • Differential Equations
Replies
16
Views
3K
Replies
2
Views
233
  • Differential Equations
Replies
31
Views
6K
Replies
2
Views
10K
  • Differential Equations
Replies
6
Views
1K
  • Differential Equations
Replies
5
Views
2K
Replies
20
Views
2K
Back
Top