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 and , the angle , the rotated frame with unit vectors and , the mass , the rod length , and the gravity vector .

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



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 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


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 as a constant. See Parameter.
Step 3: Create the angle coordinate


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 . The initial value of 1 radian is the starting angle. See Generalized Coordinate.
Step 4: Create the rotated frame



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 about the out-of-plane axis . See Frame.
Step 5: Create the rod vector


Tap the plus sign under Vector and enter
name: r
ref_frame_key: E
x: l
and tap Ok. This creates the vector , along the axis of the rotated frame, with the constant length . See Vector.
Step 6: Create the point


Tap the plus sign under Point and enter
vector_key: r
and tap Ok to create point a at the end of the vector . 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



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 axis by the angle , 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



Tap the plus sign under Rigid Translation and enter
ref_frame_key: E
x: 1
and tap Ok. This creates a vector along the 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




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 , 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




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).






What you built
The Equations section of the report shows a mass matrix and a forcing vector. For this model, with the rod length (the offset in the Joints path), they are
so the equation of motion is
Here is measured from the horizontal axis, because the rod lies along . The pendulum hangs at rest at . If you measure the angle from the hanging position instead, with , this becomes the familiar . For small swings its period is , about 2.0 s for m and m/s². This pendulum starts 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 →