Differential Equation of a Pendulum

Click For Summary
The discussion focuses on solving the differential equation for a pendulum's angle of displacement using MATLAB, where the user encounters unexpected results. The main issue arises from using Euler's method, which tends to accumulate errors and does not conserve energy, leading to an unrealistic increase in amplitude. It is noted that the differential equation must be expressed in radians, as using degrees can cause inaccuracies. Suggestions include switching to a more accurate numerical integration method and incorporating damping to model realistic behavior. The conversation emphasizes the importance of proper numerical techniques and understanding the physics behind the pendulum's motion.
  • #31
Orodruin said:
The numerical factor of second term should be 2.


The term before the square root should be ##\zeta##. If not you would not have purely imaginary roots for ##\zeta = 0##.
I fixed those two errors in my post. Thank you very much!
 
Physics news on Phys.org
  • #32
Tygra said:
Unfortunately, Vela, no. It is still behaving like haruspex said.

View attachment 355961
This is the problem you should be attacking prior to adding things like drag. If one cannot get even the simplest case to behave more or less correctly it is time to change techniques. In the case of an undamped pendulum, the peak amplitude during each cycle should remain more or less constant.

In the case of Euler's method applied to an undamped pendulum, this technique inevitably accumulates energy and eventually swings over the top. How long it takes this to happen depends on the step size. Decrease the step size and it will still happen, at least up to a point. At some point, you'll reach the problem of 1+1e-16 is exactly 1 on most computers. With too small a step size, any numerical integrator will eventually produce a non-moving pendulum, but it will take a long, long time to achieve that nonsense result.

In contrast, the symplectic Euler method tends to have total energy (and hence peak amplitude) oscillate a bit about the true value from step to step. There are much better symplectic integrators than symplectic Euler. You'll be able to take much bigger steps compared to symplectic Euler with those better techniques and still maintain good accuracy.

I mentioned leapfrog in a previous reply. Leapfrog is symplectic and is still simple to implement but it is much better than is symplectic Euler. Leapfrog lets one double the step size at no cost to accuracy, or it lets one keep the same step size with significantly better accuracy than symplectic Euler. Using bigger steps is important because the number of calls to the derivative function is a key driver of the computational cost. A technique that lets one double the step size at no cost to accuracy halves the number of derivative function calls. People have developed much higher order symplectic integrators than leapfrog.

If you take a class that covers numerically integrating an initial value problem (an ODE with given initial values), one of the first things the instructor will teach is almost inevitably Euler's method. The next thing you will be taught is to never use Euler's method, with examples. Euler's method is fine for teaching because it introduces the subject. In addition, several better integrators use Euler-like steps as intermediate steps. It's important to learn Euler's method. It's also important to learn not to use it.
 
  • #33
Tygra said:
What about using the Runge Kutta Technique? Would that be better?

If by "the Runge-Kutta Technique" you mean the classical RK4 algorithm, then yes, that would be significantly better (but see the caveat below). Do note, however, that as @haruspex noted, there is no one Runge-Kutta technique. Runge-Kutta is instead a family of techniques, conceptually infinite in size.

The caveat is that the classical RK4 algorithm does not conserve energy. No technique that rewrites a system of ##N## second order ODEs as a system of ##2N## first order ODEs is going to conserve energy. IIRC, classical RK4 tends to lose energy.

The upside of classical RK4 versus explicit Euler is that far, far fewer steps are typically needed for classical RK4 compared to explicit Euler to achieve the same accuracy. Classical RK4 makes four derivative calls per integration step. If RK4 enables the step size to be increased by more than a factor of four without harm compared to explicit Euler, then using classical RK4 is a win. Typically, switching from explicit Euler to classical RK4 enables increasing the step size by orders of magnitude (not just a factor of four or so). This typically makes RK4 a big win without being monstrously complex.

That said, there are some regimes where switching from explicit Euler to classical RK4 is a big lose, and that is when the very small step size is not only mandated by explicit Euler but also is mandated for physical reasons. For example, molecule-level simulations need very small time steps as they occasionally exhibit very fast dynamics during near collisions. In such cases, it is almost always symplectic Euler or some other simple symplectic technique such as leapfrog that is used instead of explicit Euler.
 

Similar threads

Replies
1
Views
1K
  • · Replies 15 ·
Replies
15
Views
1K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 14 ·
Replies
14
Views
1K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 21 ·
Replies
21
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K