Skip to content

Latest commit

 

History

History
120 lines (88 loc) · 3.22 KB

readme.md

File metadata and controls

120 lines (88 loc) · 3.22 KB

Build Status Code coverage codecov License: MIT

Pendulum simulator

Mechanical simulation of non-inertial pendula.

By Pablo Rodríguez-Sánchez

Non-inertial pendula

Double pendulum (inertial and non-inertial)

Damped pendulum

Installation

git clone https://github.com/PabRod/pendulum
cd pendulum
python setup.py install --user

Tests

We are using pytest for unit testing. Run it via:

pytest

Getting started

Tutorial

Printer friendly tutorial available here

Minimal example

This is a minimal example of the usage of this package:

## Import the required modules
from pendulum.models import *
import matplotlib.pyplot as plt

## Set-up your problem
l = 1.5 # Length
g = 9.8 # Gravity
d = 0.5 # Damping

ts = np.linspace(0, 10, 1000) # Simulation time
yinit = (0, 1) # Initial condition (th_0, w_0)

## Solve it
sol = pendulum(yinit, ts, l = l, g = g, d = d)

## Plot results
fig, axs = plt.subplots(1, 1)
plt.plot(ts, sol[:,0], label = r'$\theta$')
plt.plot(ts, sol[:,1], label = r'$\omega$')

plt.xlabel('time')
plt.ylabel('states')

plt.legend()
plt.show()

Accelerated pendulum

Example illustrating how to input the pivot's movement (for an animated version of this problem, see next subsection).

## Import the required modules
from pendulum.models import *
import matplotlib.pyplot as plt

## Set-up your problem
l = 1.5 # Length
g = 9.8 # Gravity
d = 0.5 # Damping

ts = np.linspace(-5, 10, 1000) # Simulation time
yinit = (0, 0) # Initial condition (th_0, w_0)

# Pivot's position
## The pivot is moving, so its position is a function of time
pos_x = lambda t : np.arctan(5*t)
pos_y = lambda t : 0*t

## Solve it
sol = pendulum(yinit, ts, pos_x, pos_y, l = l, g = g, d = d)

## Plot results
fig, axs = plt.subplots(1, 1)
plt.plot(ts, sol[:,0], label = r'$\theta$')
plt.plot(ts, sol[:,1], label = r'$\omega$')

plt.xlabel('time')
plt.ylabel('states')

plt.legend()
plt.show()

More examples

For more advanced examples, see