• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Animations of random double pendulums

Double pendulum

The code behind @pendulum_bot Twitter bot which posts animations of a double pendulum released from a random position to swing for 30 seconds.

 

Basic usage

To create an animation of a random double pendulum:

>>> from simulation import create_random_example, simulate
>>> from animations import single_animation
>>> rand_ex = create_random_example()
>>> results = simulate(rand_ex)
>>> single_animation(results, rand_ex)

The animation is saved as .mp4 video in animations subdirectory.


To create an animation and post it on Twitter, a valid API key is needed, and should be stored in api_key.txt.

>>> from tweet_it import new_tweet
>>> new_tweet() # creates a new animation of random double pendulum
# or
>>> new_tweet('existing_file', 'My custom Twitter status')

To create double pendulum with the exact values for initial conditions:

>>> from pendulum import Pendulum, DoublePendulum
>>> p1 = Pendulum(m=2.7, x=2.5, y=3.7, u=0, v=0)
>>> p2 = Pendulum(m=3.1, x=0.2, y=6.3, u=0, v=0)
>>> dp = DoublePendulum(p1, p2)

To create multiple pendulums with slight perturbations of initial conditions to observe chaotic behaviour:

>>> from simulation import create_random_example, create_perturbations, simulate_multiple_examples
>>> from animations import multi_animation
>>> rand_ex = create_random_example()
>>> perturbed = create_perturbations(10, rand_ex, amount=1e-5)
>>> results = simulate_multiple_examples(perturbed)
>>> multi_animation(results, rand_ex)

 

Installation

git clone https://github.com/narimiran/double_pendulum.git
cd double_pendulum

Dependencies

  • Python 3
  • numpy (running simulations)
  • matplotlib (creating animations)
  • ffmpeg or avconv/libavtools (saving videos)
  • twython (posting Twitter updates)

 

FAQ

Q: Why do you use Cartesian coordinates? I prefer polar coordinates.

A: The initial task I was given was to implement double pendulum as DAE system in Cartesian coordinates. The idea for animations and Twitter bot came later, and Cartesian coordinates remained.

Q: Which Runge-Kutta methods can I use?

A: Any of these:

  • Forward Euler (Euler)
  • Explicit midpoint (ExplicitMidpoint)
  • Ralston's method (Ralston)
  • Kutta's 3rd order method (Kutta3)
  • the Runge-Kutta 4th order method (RK4)
  • Runge-Kutta-Fehlberg (RKF)
  • Cash-Karp (Cash-Karp)
  • Dormand-Prince method (DOPRI5)

Q: Why can't I use implicit Runge-Kutta methods?

A: Implicit methods require different solving method (solving a system of non-linear equations). This is not (yet) implemented.

Q: Is there any damping/friction?

There is no damping and no friction. The only force acting on the system is gravity.

Q: Couldn't all/some of this be done simpler?

A: Probably.

 

License

MIT License

More Repositories

1

tably

Python command-line script for converting .csv data to LaTeX tables
Python
213
star
2

itertools

Nim rewrite of a very popular Python module of the same name.
Nim
134
star
3

nim-basics

Source files for Nim basics tutorial
HTML
102
star
4

AdventOfCode2017

My solutions for AoC 2017, using Nim, OCaml, and Python
OCaml
42
star
5

scopy

Python script for searching through your digital books and cataloguing them in an easy-to-share list of files.
Python
31
star
6

AdventOfCode2020

My solutions for AoC 2020
Nim
29
star
7

sorta

SortedTables in Nim, based on B-Trees
Nim
17
star
8

AdventOfCode2021

My solutions for AoC 2021
Python
14
star
9

AdventOfCode2018

My Nim solutions for Advent of Code 2018
Nim
13
star
10

AdventOfCode2022

My solutions for AoC 2022
Clojure
12
star
11

advent_of_code_2015

My solutions for Advent of Code 2015
Nim
10
star
12

checkio

my solutions for the problems on checkio.org
Python
9
star
13

AdventOfCode2023

My solutions for Advent of Code 2023
Clojure
8
star
14

sha3

Taken over from @tankfeeder (https://bitbucket.org/mihailp/)
Nim
6
star
15

narimiran.github.io

Source code for my personal blog.
SCSS
6
star
16

advent_of_code_2016

My solutions for Advent of Code 2016
Clojure
5
star
17

blake2

Taken over from @tankfeeder (https://bitbucket.org/mihailp/)
Nim
4
star
18

amaze

aMAZE: amazing maze
Clojure
3
star
19

AdventOfCode2019

My OCaml solutions for Advent of Code 2019
OCaml
2
star
20

advent_of_nim_2016

Learning Nim by solving AoC 2016 tasks
Nim
2
star
21

kaggle

My notebooks for Kaggle problems
Jupyter Notebook
1
star
22

data-notebooks

My data science notebooks
Jupyter Notebook
1
star
23

cljox

Clojure implementation of `jlox` interpreter for the Lox programming language
Clojure
1
star