File:Driven-pendulums-resonance-animation.gif

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Driven-pendulums-resonance-animation.gif(220 × 136 pixels, file size: 120 KB, MIME type: image/gif, looped, 100 frames, 4.0 s)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
English: Animation of three identical pendulums of resonance frequency ω0 and damping D=0.05. The pendulums are driven with the same strength, but different driving frequencies ω:
  • left: ω=2/3ω0
  • center: ω=ω0
  • right: ω=4/3ω0
One can see that the pendulums driven below and above resonance oscillate less, whereas the pendulum at resonance oscillates strongest. The pendulums also show different relative phases relative to the drive.
Date
Source Own work
 
This plot was created with Matplotlib.
Author Geek3

Source Code[edit]

The plot was generated with Python Matplotlib.


Python Matplotlib source code
#!/usr/bin/python
# -*- coding: utf8 -*-

import os
import inspect
from math import *
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import animation

# settings
mpl.rcParams['path.snap'] = False
fname = 'driven-pendulums-resonance-animation'
size = 220, 136
nframes = 100

susp = 16
f0 = 3.0
pendulums = [
{'x0':29, 'y0':117.5, 'f':2.0, 'A':4, 'D':0.05, 'l':89, 'phi0':0.},
{'x0':110, 'y0':117.5, 'f':3.0, 'A':4, 'D':0.05, 'l':89, 'phi0':0.},
{'x0':191, 'y0':117.5, 'f':4.0, 'A':4, 'D':0.05, 'l':89, 'phi0':0.}]

for p in pendulums:
    D = p['D']
    eta = p['f'] / f0
    # use harmonic approximation
    p['Arel'] = 1.0 / sqrt((1. - eta**2)**2 + (2.*eta*D)**2)
    p['Phaserel'] = atan2(2 * eta * D, 1.0 - eta**2)

def animate(nframe, saveframes=False):
    print nframe, nframes
    t = float(nframe) / nframes
    
    plt.clf()
    fig.gca().set_position((0, 0, 1, 1))
    plt.xlim(0, size[0])
    plt.ylim(0, size[1])
    plt.axis('off')
    
    for p in pendulums:
        dxSusp = p['A'] * sin(p['phi0'] + 2*pi*p['f']*t)
        dsPend = p['A'] * sin(p['phi0'] + 2*pi*p['f']*t - p['Phaserel']) * p['Arel']
        PhiPend = (dsPend - dxSusp) / p['l']
        dxPend = dxSusp + p['l'] * sin(PhiPend)
        dyPend = -p['l'] * cos(PhiPend)
        
        xSusp = p['x0'] + dxSusp
        xPend = p['x0'] + dxPend
        yPend = p['y0'] + dyPend
        
        # draw pendulum
        s = 0.72
        plt.plot([p['x0'] - susp, p['x0'] + susp],
                 [p['y0'], p['y0']], '-k', lw=3)
        plt.plot([xSusp, xPend], [p['y0'], yPend], '-k', lw=1.5)
        plt.plot([xSusp], [p['y0']], '.k', markersize=12)
        plt.plot([xPend], [yPend], 'o', color='#aaaaaa',
                 markersize=14, markeredgewidth=1.5)
    
    if saveframes:
        # export frame
        dig = int(ceil(log10(nframes)))
        fsavename = ('frame{:0' + str(dig) + '}.svg').format(nframe)
        fig.savefig(fsavename)
        with open(fsavename) as f: content = f.read()
        content = content.replace('pt"', 'px"').replace('pt"', 'px"')
        with open(fsavename, 'w') as f: f.write(content)

fig = plt.figure(figsize=(size[0]/72., size[1]/72.))

#anim = animation.FuncAnimation(fig, animate, frames=nframes)
#anim.save(fname + '.gif', writer='imagemagick', fps=25)

# use imagemagick on svgs rather than builtin imagemagick support
# this avoids snapping and offers some custom settings
os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
for i in range(nframes):
    animate(i, True)
os.system('convert -loop 0 -delay 4 frame*.svg +dither -posterize 16 ' + fname + '.gif')
for i in os.listdir('.'):
    if i.startswith('frame') and i.endswith('.svg'):
        os.remove(i)

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
You may select the license of your choice.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current21:08, 10 April 2016Thumbnail for version as of 21:08, 10 April 2016220 × 136 (120 KB)Geek3 (talk | contribs)smaller drive amplitude
20:57, 10 April 2016Thumbnail for version as of 20:57, 10 April 2016220 × 136 (121 KB)Geek3 (talk | contribs){{Information |Description ={{en|1=Animation of three identical pendulums of resonance frequency ''ω''<sub>0</sub> and damping ''D''=0.1. The pendulums are driven with the sam...

The following 2 pages use this file:

File usage on other wikis

The following other wikis use this file:

Metadata