Simulation and Animation of a Linear and Nonlinear Pendulum Model

Demonstrates how to use both movie2avi and VideoWriter to generate avi files from simulation data.
Updated 10 Apr 2012

View License

AnimatePendulum.m simulates and animates a simple pendulum using both linear and nonlinear dynamic models. A larger difference is observed between linear and nonlinear models when maximum angular position is large. This condition can be achieved by specifying either a large initial angle or velocity.

After simulation of both the linear and nonlinear models the code steps through each time step and plots the pendulum as well as its position and velocity trajectories. These plots are recorded using the getframe command, and then used to produce a video of the animation using both the movie2avi and VideoWriter commands.

Several videos based on this code are available on YouTube: (linear simulation) (small angle comparison) (large angle comparison)

Cite As

James Allison (2024). Simulation and Animation of a Linear and Nonlinear Pendulum Model (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes