# Modeling and Simulating Pendulum Motion

I've been having difficulty creating a mathematical model of a pendulum in my code. While there is plenty of info on general equations describing a the motion of a pendulum, I seem to be having difficulty translating those into code, or more specifically cartesian coordinates. These difficulties no doubt stem from my poor math skills, thus, I am looking for help.

My initial thought before even researching the matter was to simply use two independent Sine Wave oscillators. I used a basic equation y(t) = A*sin(ω*t+φ). I think that its probably worth mentioning here that while I understand what that equation does. I'm not 100% clear one why it behaves periodically. Of course have dealt with trigonometric ratios before, but I don't feel like I have a grasp on the actual concepts behind it. I don't fully appreciate all of its consequences I guess.

Anyways, I initially figured I could determine the x coordinate and the y coordinate using 2 separate sine wave oscillators, while having the period of the y oscillator be half of the value of the x oscillator. This however (possibly obvious to you...) resulted in something closely resembling lissajous curves.

Now I've been reading explanations on the movement of a pendulum, yet while reading I get lost at two points regardless of the source I am reading from.

First of all, everyone refers to a differential equation that I don't understand, probably due to never taking calculus. Here is a link to them all... http://hyperphysics.phy-astr.gsu.edu/hbase/pend.html#c3

And secondly, how can I derive two separate coordinates from one of these equations?

-
As a primer, you might want to look up Polar Coordinates. Your pendulum is most naturally described by the angle $\theta$, from which you obtain $x$ and $y$ using trigonometry. –  Lagerbaer May 14 '11 at 21:47
Yeah, I had done that i think. I wrote a function and used its output like... r*cos(oscil(t)), r*sin(oscil(t))... –  Pete May 14 '11 at 22:02

Forget about the motion for a moment. First just consider a pendulum of length $\ell$ at an angle $\vartheta$ from rest. If $(0,0)=0\mathbf{e}_x+0\mathbf{e}_y$ is where the pendulum is attached, then the end of it is at $$\bigl(\ell\cdot\sin(\vartheta), -\ell\cdot\cos(\vartheta)\bigr)$$

So, now let's describe the motion in terms of these variables. $\ell$ would usually be constant, so we don't need to care about this. It's $\vartheta$ that varies in time, so we get $$y(t) = -\ell\cdot\cos(\vartheta(t)),$$ $$x(t) = \ell\cdot\sin(\vartheta(t)),$$ Unfortunatly, we don't know $\vartheta(t)$ yet. We can either

1. Assume that it does oscillate harmonically, that is, $\vartheta(t)=A\cdot\sin(\omega t)$ for some $A$ and $\omega$, which is often a good approximation.
2. Decide we can do better, which is necessary if you consider big angles like $30^\circ$.

Lets stick to small angles here. $\vartheta(t)=A\cdot\sin(\omega t)$ with $A\ll1$. We can then try to further simplify the cartesian coordinate representations: in $$x(t) = \ell\cdot\sin(\vartheta(t)) = \ell\cdot\sin\bigl(A\cdot\sin(\omega t)\bigr),$$ we can use that $A\cdot\sin(\omega t)\ll 1$ and $\sin(x)\approx x$ for $x\ll 1$, therefore $$x(t) \approx \ell\cdot A\cdot\sin(\omega t).$$ In $$y(t) = -\ell\cdot\cos(\vartheta(t)) = -\ell\cdot\cos\bigl(A\cdot\sin(\omega t)\bigr),$$ we can use that $\cos(x)\approx 1-\tfrac{x^2}2$ for $x\ll 1$, therefore $$y(t) \approx \ell\cdot \bigl(\tfrac{A^2}2\cdot\sin^2(\omega t)-1\bigr)$$ which, due to $\sin^2(x)=\tfrac12-\tfrac12\cos(2x)$, can be further simplyfied to $$y(t) \approx \tfrac{A^2}{4}\ell\cdot\cos(2\omega t) - \tfrac\ell2.$$ As you see, two harmonic oscillators is in fact not such a bad assumption, and the important thing is that $y$ must oscillate at twice the frequency of $x$.

When I say $\sin(x)$ is approximately $x$, I mean just what I say: if you look at the sine function, and "zoom in" very close to 0 (that is, $x\ll1$, for instance $x=.001$), then this function looks very much like the simple $f(x)=x$. http://www.wolframalpha.com/input/?i=plot+sin%28x%29+from+-.01+to+.01 It's just when you look very carefully that you notice it's in fact bent a little bit.