Mechanical simulation of non-inertial pendula.
git clone https://github.com/PabRod/pendulum
cd pendulum
python setup.py install --user
We are using pytest
for unit testing. Run it via:
pytest
Printer friendly tutorial available here
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()
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()
For more advanced examples, see