File: coupled.ode

package info (click to toggle)
plotutils 2.0-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 5,964 kB
  • ctags: 2,522
  • sloc: ansic: 38,416; sh: 1,853; yacc: 856; makefile: 181; lex: 144
file content (39 lines) | stat: -rw-r--r-- 860 bytes parent folder | download
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:
#
#    <coupled.ode ode | graph -TX -C
# 
# or alternatively, to get a real-time plot,
#
#    <coupled.ode ode | graph -TX -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