Predicting Pendulum Position: Differential Equations in C++ Code

  • Thread starter Thread starter franznietzsche
  • Start date Start date
  • Tags Tags
    Modeling Pendulum
Click For Summary
The discussion centers on a C++ program designed to predict the position of a pendulum using differential equations, specifically the motion equations. The user experiences issues with the simulation, where the pendulum's amplitude and period increase unrealistically, leading to nonsensical results such as a position of -18 radians after 10 seconds. Contributors point out that the original equations used were incorrect, suggesting the need for the correct form of angular acceleration, which should include a negative sign. The conversation also highlights the importance of using numerical methods like the Runge-Kutta algorithm for better accuracy in approximating the pendulum's motion. Ultimately, the user is encouraged to refine their implementation to achieve more realistic oscillatory behavior.
  • #61
Nice link Krab. What I fail to see there is any formal error analysis of the methods. The claim that the "failure to conserve energy" property of Euler is characteristic to periodic functions is not proven. They only show 1 step size, what would happen if they choose a smaller step? What would happen if they chose a DIFFERENT function. The local discretization error of Euler is ~step size, this holds for ALL applications of Euler,not just periodic.

Here is an expression derived in Conte and de Boor which relates step size and local error.

|f_y(x,y)|\leq L
|y^{\prime\prime}(x)|<Y
|{error}_n|= \frac{hY}{2L}(e^{(x_n-x_0)L}-1)

He points out that this is a "Upper bound rather then a realistic bound" so you may be able to achieve the same error with a smaller step. But a step size computed with this formula will yield the desired error at the specified end point.

Notice that this error is indeed monotonic. So for the pendulum it shows up as a steadily increasing amplitude. Some one with no deeper vision could indeed say that it looks like energy is not conserved. But that is failing to look at the mechanism of the tool being applied. (Failure: Car won't run, solution: Replace engine, root cause: out of gas) Further, if you were apply this method to a different system (perhaps financial) would it still fail to conserve energy? Of course not, because energy is not involved, but it would still show a steady increase in the final solution. So to say Euler fails to conserve energy is to broad a statement. It can only be make for specific models. While when I say Euler has local discretization of ~step this applies to ALL applications of Euler, and is the root cause of the failure to conserve energy phenomena in the pendulum problem.
 
Last edited:
Physics news on Phys.org
  • #62
Originally posted by krab
Look here
for a comparison of Euler, Euler-Cromer, Runge-Kutta methods. It includes Matlab scripts.

In particular, notice that the straight Euler method gives energy error that grows exponentially; so whoever claimed first that Euler method is unstable for periodic motion appears to be correct.

I've done a lot of this kind of problem and have always used RK; it has never let me down.

I just did two separate runs one using Euler and one using Euler-Cromer both with dt = 0.01. Euler-Cromer was very accurate at 100 seconds and gave the correct time for the equilibrium points to within a factor of 0.03 of the period predicted by Newton's equation. When i did the run with Euler's Method however soemthing interesting happened. The period became longer, however energy was conserved to the same degree it had been with Euler-Cromer. I noted no difference in amplitude of either velocity or position, though the period was longer, but only marginally so. At 100 seconds Eulers method was about a second behind the Euler-Cromer method.
 
  • #63
I have seen similer results, where the amplitude (energy) remained consitent but the period was incorrect. It did not seem to creep out, it was just wrong. Not real sure why that happens. I wondered if I was writing to the wrong data file.
 

Similar threads

  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
Replies
7
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K