GithubHelp home page GithubHelp logo

pabrod / pendulum Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 6.26 MB

Mechanical simulation of simple and double non-inertial pendula

License: MIT License

Python 100.00%
mechanics mechanical-engineering physics-simulation physics pendulum

pendulum's Introduction

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

pendulum's People

Contributors

pabrod avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

julestevez

pendulum's Issues

Sloppy differentiation

The numerical differentiation in the method ni_pendulum, part of models.py is artisanal and open to improvement.

Implement a standard method. More information here.

Possible bug

The sign of accel_y in the non-inertial pendulum seems to be wrong.

Improve integration

Something is wrong with the integrators in example_stopping.py.

The first step leads to a sudden change in the state.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.