Simple Pendulum

On this page

Introduction

This tutorial builds a simple pendulum: a point mass on a rigid, massless rod, with one rotational degree of freedom (DOF), in a uniform gravitational field. By the end you will have derived its equation of motion, simulated it and exported it as Python.

The figure below shows the system: the inertial frame with unit vectors nx\mathbf{n}_x and ny\mathbf{n}_y, the angle θ\theta, the rotated frame with unit vectors ex\mathbf{e}_x and ey\mathbf{e}_y, the mass mm, the rod length ll, and the gravity vector g\mathbf{g}.

Schematic of the pendulum: a mass m on a rod of length l, at angle theta from the horizontal x axis, with gravity g pointing down

Two ways to build the same model

MOMDYN has two kinematics interfaces, and they build exactly the same pendulum. You only need one of them. Path A: Classic is like a pencil-and-paper derivation: you name each parameter, then create the frame, vector and point from them. Path B: Joints is closer to other multibody software: a revolute joint and a rigid translation replace those five steps with two. Both paths start at Step 1 and continue at Step 7.

Set up the model

Step 1: Create the new model

The Welcome screen with the Create, Import and Help buttonsThe top of the Create settings dialog with the model name and description fieldsThe bottom of the Create settings dialog with the gravity, time and tolerance fields

From the Welcome screen, tap Create. A dialog titled “Create - Specify Settings” opens (see the settings reference). Most settings can keep their defaults. Enter the following:

  • model_name: Pendulum

  • model_description: A simple pendulum with a point mass and single angular degree of freedom

  • gravity_method: Uniform

  • gravity_constant: 9.8

  • gravity_direction: -Y

  • time_duration: 5

  • tol: 0.00001

Tap the green check in the lower right. A blank diagram opens. Save the model now (menu drawer, then Export, with Save File on), because the Joints path returns to this point.

Path A: Classic interface

The empty diagram view before any symbols are createdThe navigation drawer with the Classic menu highlighted

The Classic interface gives direct control over the building blocks of the kinematics. If you prefer fewer steps, jump to Path B: Joints.

Step 2: Create the length parameter

The Classic menu with a plus button under ParameterThe New Parameter dialog filled in with name l, value 1 and description length

Tap the menu button (three horizontal bars) in the upper left to open the navigation drawer, open the Classic menu and tap the plus sign under Parameter. Enter

  • name: l

  • value: 1

  • description: length

and tap Ok. This creates the rod length ll as a constant. See Parameter.

Step 3: Create the angle coordinate

The Classic menu with a plus button under Generalized CoordinateThe New Generalized Coordinate dialog filled in with name theta, initial value 1 and description angle

With the Classic menu open, tap the plus sign under Generalized Coordinate and enter

  • name: \theta

  • initial: 1

  • description: angle

Entering \theta creates the symbol θ\theta. The initial value of 1 radian is the starting angle. See Generalized Coordinate.

Step 4: Create the rotated frame

The Classic menu with a plus button under FrameThe New Frame dialog with first_angle set to theta(t)The new rotated frame drawn at the origin of the diagram view

Tap the plus sign under Frame and enter (items not listed keep their defaults)

  • first_angle: θ(t)

and tap Ok to create the frame. It is rotated by the angle θ\theta about the out-of-plane axis k\mathbf{k}. See Frame.

Step 5: Create the rod vector

The New Vector dialog with name r, ref_frame_key E and x set to lThe new vector drawn as a gray line along the x axis of the rotated frame

Tap the plus sign under Vector and enter

  • name: r

  • ref_frame_key: E

  • x: l

and tap Ok. This creates the vector r\mathbf{r}, along the ex\mathbf{e}_x axis of the rotated frame, with the constant length ll. See Vector.

Step 6: Create the point

The New Point dialog with vector_key set to rThe diagram showing the rotated frame, the rod vector and the new point at its end

Tap the plus sign under Point and enter

  • vector_key: r

and tap Ok to create point a at the end of the vector r\mathbf{r}. Close the edit menu with the three bars: the diagram now shows the frame, the vector and the point. See Point. Continue at Step 7.

Path B: Joints interface

The Joints interface consolidates the building blocks into common mechanical joints, so you do not have to create each symbol, frame, vector and point yourself.

Step 2 (Joints path): Add a revolute joint

The navigation drawer with the Joints menu highlightedThe Joints menu with a plus button under RevoluteThe New Revolute joint dialog with name E, motion_axis +Z and value 1

Tap the Welcome tab at the bottom of the screen, then Import, and choose the saved Pendulum model. This returns the model to its state after Step 1. Open the navigation drawer, open the Joints menu and tap the plus sign under Revolute. Enter (items not listed keep their defaults)

  • name: E

  • motion_axis: +Z

  • value: 1

and tap Ok. This creates a frame rotated about the out-of-plane k\mathbf{k} axis by the angle θE\theta_E, the same result as Steps 3 and 4 above. The joint creates the generalized coordinate and the frame in a single object. See Revolute Joint.

Step 3 (Joints path): Add a rigid translation

The Joints menu with a plus button under Rigid TranslationThe New Rigid Translation dialog with ref_frame_key E and x set to 1The diagram showing the revolute joint frame, a rod along its x axis and a point at the end of the rod

Tap the plus sign under Rigid Translation and enter

  • ref_frame_key: E

  • x: 1

and tap Ok. This creates a vector along the ex\mathbf{e}_x axis of length 1 and a new point a, the same result as Steps 5 and 6 above. The kinematics that took five steps in the Classic interface took two joints here. See Rigid Translation.

Add the mass

Step 7: Add the point mass

The navigation drawer with the Bodies menu highlightedThe Bodies menu with a plus button under ParticleThe New Particle dialog with name bob, ref_point_key a and mass 1The particle drawn as a sphere at the end of the pendulum rod

Open the Bodies panel and tap the plus sign under Particle. Enter

  • name: bob

  • ref_point_key: a

  • mass: 1

This creates the pendulum bob with mass 1, represented by the symbol mbobm_{bob}, attached to point a. See Particle.

Simulate and analyze

Step 8: Derive the equations and simulate

On the Diagram tab, tap the right-arrow button in the lower left to derive the equations of motion. This model is small, so the derivation runs nearly instantly, and the icon changes to the outline of a play button. Tap again to run the simulation, which is also nearly instant, and tap once more to play the animation. The pendulum starts 1 radian above the horizontal and swings down through the vertical, with a period of about 3.4 seconds, as in the animation at the top of this page. The on-screen controls are described in On-Screen Controls.

Step 9: Export the model

The Export button in the menu drawerThe Export screen with switches for the model file, the Python file and the simulation dataThe exported Python code opened in the Pyto appA plot of the pendulum's angle and angular rate against time

Open the menu drawer and tap Export. Switch on the items you want, then export:

  • Save File (model.py): the model, in the format MOMDYN imports.

  • Python File (python_model.py): code you can run and extend on a desktop Python environment.

  • Tabular Data (simulation.csv): the time series of the generalized coordinates and speeds that drive the animation.

  • Plot Images (plots.pdf): plots of the simulation results.

See Import/Export for the file formats.

Step 10: Read the report

Tap the Report tab to see the model as text, equations and plots. The buttons at the top choose the section: symbols, frames, points, bodies, loads, equations and plots. The images show these sections for the pendulum (there are no loads other than gravity).

The Symbols section of the report, listing the length, the angle and the massThe Frames section of the report, listing the inertial frame and the rotated frame EThe Points section of the report, listing the origin and point aThe Bodies section of the report, listing the particle bobThe Equations section of the report, showing the mass matrix and the forcing vectorThe Plots section of the report, showing the angle and angular rate over time

What you built

The Equations section of the report shows a mass matrix and a forcing vector. For this model, with the rod length ll (the offset xAx_A in the Joints path), they are

M=mbob l2,F=−mbob g lcos⁡θM = m_{bob}\,l^2, \qquad F = -m_{bob}\,g\,l\cos\theta

so the equation of motion is

m l2 θ¨+m g lcos⁡θ=0⟺θ¨=−glcos⁡θm\,l^2\,\ddot{\theta} + m\,g\,l\cos\theta = 0 \quad\Longleftrightarrow\quad \ddot{\theta} = -\frac{g}{l}\cos\theta

Here θ\theta is measured from the horizontal nx\mathbf{n}_x axis, because the rod lies along ex\mathbf{e}_x. The pendulum hangs at rest at θ=−π/2\theta = -\pi/2. If you measure the angle from the hanging position instead, with φ=θ+π/2\varphi = \theta + \pi/2, this becomes the familiar φ¨+(g/l)sin⁡φ=0\ddot{\varphi} + (g/l)\sin\varphi = 0. For small swings its period is 2πl/g2\pi\sqrt{l/g}, about 2.0 s for l=1l = 1 m and g=9.8g = 9.8 m/s². This pendulum starts 1+π/2≈2.571 + \pi/2 \approx 2.57 rad from hanging, a swing of about 147 degrees, which is why its period is longer, about 3.4 s.

Exported Python

The Python File export contains the equations of motion and a short simulation script. This is an excerpt:

python_model.py (placeholder excerpt)

# TODO (owner): paste a short excerpt of the exported pendulum code here
# (the equations of motion and the simulation call).

Next steps

Reference pages for the components used here: Parameter, Generalized Coordinate, Frame, Vector, Point, Revolute Joint, Rigid Translation and Particle.

Build this model in MOMDYN, free on iPhone & iPad

Everything in this tutorial runs in the app. No license required.

Next tutorial: Mass-Spring-Damper →
Download on the App Store
Search the docs