File: coupled.ode

package info (click to toggle)
plotutils 2.4.1-15
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,072 kB
  • ctags: 6,952
  • sloc: ansic: 76,305; cpp: 12,402; sh: 8,475; yacc: 2,604; makefile: 894; lex: 144
file content (39 lines) | stat: -rw-r--r-- 864 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# This example simulates two similar pendulums, coupled with a horizontal
# spring.  The motion is taken to be undamped.
# 
# The plot shows the displacement of one of the pendulums, as a function of
# time.  It illustrates how energy (e.g. maximum displacement) oscillates
# back and forth between the two.

# You may run this example by doing:
#
#    ode < coupled.ode | graph -T X -C
# 
# or alternatively, to get a real-time plot,
#
#    ode < coupled.ode | graph -T X -C -x 0 50 -y -0.6 0.6

# The equations are:
# m*x1'' = - m*g*x1/l + k(x2 - x1)
# m*x2'' = - m*g*x2/l - k(x2 - x1)

xone' = vxone
xtwo' = vxtwo

vxone' = -g*xone/lone + k/mone * ( xtwo - xone)
vxtwo' = -g*xtwo/ltwo - k/ltwo * ( xtwo - xone)

k = 1
g = 9.8		# acceleration due to gravity
lone = 5
ltwo = 5
mone = 1
mtwo = 1

xone = 0.0
xtwo = 0.3
vxone = 0
vxtwo = 0

print t, xone
step 0,50