Pendulum problem

BlitzPlus Forums/BlitzPlus Programming/Pendulum problem

KrissCross(Posted 2014) [#1]
Hi! I wanted to create a simulation of a pendulum so I did some researcher on equations to use. After a while I found this one:
Fa = -mg*Sin(angle). I tried to create a pendulum based on that formula but I failed. What am I doing wrong?




Who was John Galt?(Posted 2014) [#2]
Can't run the code here, but I suspect that the problem is the size of your 'timestep'.

Try introducing a timestep variable dt#=0.01

angle=angle+Fa*dt

See if that helps. You can experiment with values of dt- generally as timestep increases the simulation strays further from the mathematical model.


Floyd(Posted 2014) [#3]
You started with a differential equation: F = m*a, meaning force equals mass times acceleration.
Thus acceleration is -g*Sin(angle). Acceleration is the second derivative of the angle with respect to time.
In principle this can be solved to give angle as a function of time. But in practice it can't.

There are two options. You can use some numerical method, such as Runge-Kutta, for dealing with differential equations.
But the usual approach is to use a simpler, but approximate, equation. For small angles Sin(angle) is almost exactly equal to angle.
Note: this is in radians, not degrees.

That gives a new differential equation of the form

acceleration = constant * angle

which can be solved exactly.

There is a nice overview here. The solution is in the box at the bottom.