Simple Pendulum Motion in Generalized Coordinates

This section provides an example of applying the Hamiltonian and the Law of Conservation of Energy to an object in simple pendulum motion using generalized coordinates.

What Is Simple Pendulum Motion? A Simple Pendulum Motion is an object of mass m hanging on a string from a pivot point so that it is constrained to move on a circle of radius L.

Let's introduce 2 generalized coordinates to describe this motion, θ and l:

```q = (θ, l)

where:
# θ is the angular position from the vertical line
# l is the length of the string
```

The transformation functions are:

```r = (x, y)

r = (r1(), r2())

r = (l*sin(θ), -l*cos(θ))
```

Then the velocity is:

```r' = dr/dt

or:
r' = (l*cos(θ)*θ', l*sin(θ)*θ')
```

Then the kinetic energy is:

```T = m*v*v/2

or:
T = 0.5*m*r'*r'

or:
T = 0.5*m*l*l*(cos(θ)**2)+sin(θ)**2)*θ'*θ'

or:
T = 0.5*m*l*l*θ'*θ'
# Since cos(θ)**2)+sin(θ)**2 = 1
```

Then the potential energy is:

```V = m*g*y

or:
V = m*g*(-l*cos(θ))

or:
V = -m*g*l*cos(θ)
```

Now put them into the Hamiltonian:

```H = T + V                          (H.1)

or:
H = 0.5*m*l*l*θ'*θ' - m*g*l*cos(θ)
```

Apply the Law of Conservation of Energy:

```T + V = constant                   (H.2)

or:
dT/dt + dV/dt = 0                (H.3)

or:
d(0.5*m*l*l*θ'*θ' - m*g*l*cos(θ))/dt = 0

or:
m*l*l*θ'*θ" + m*g*l*sin(θ)*θ' = 0

or:
l*θ" + g*sin(θ) = 0
# Cancel out common factors
```

As you can see, using generalized coordinates can given a simple form for the equation of motion of a given physical system.