File: duck.ode

package info (click to toggle)
xppaut 8.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,332 kB
  • sloc: ansic: 74,690; makefile: 127; sh: 92
file content (31 lines) | stat: -rwxr-xr-x 953 bytes parent folder | download | duplicates (3)
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
# duck.ode
# the infamous drinking duck
# modeled as a pendulum with some extra forces
# M is the total mass of the two parts of the duck
# m1 is the lower mass and M-m1 the upper
# mmin is the mass of the two parts when empty
# thus, M-2*mmin is the mass of the fluid
# we will call mu the mass of th is fluid in the lower vessel
# without loss of generality we assume this is 1 so M=1+2*mmin
mudot=-eps*abs(xdot)*min(beta*mu,1)
m1=mmin+mu
m2=mmin+mutot -mu
mu'=mudot
x'=xdot
xdot'=(-f*xdot-(m1*l1-m2*l2)*sin(x)+k/(1-cos(x-xlo))-mudot*(l1^2-l2^2))/(m1*l1^2+m2*l2^2)
par l1=2.6,l2=2.5,mmin=2,f=.5,k=.002,xlo=-.2,eps=.015,xdip=1.6,mutot=.4
par beta=50
global 1 x-xdip {xdot=0;mu=mutot}
init mu=.25,x=1.5
# some animation constants
x1=.5+.8*(l1/(l1+l2))*sin(x)
y1=.5-.8*(l1/(l1+l2))*cos(x)
x2=.5-.8*(l2/(l1+l2))*sin(x)
y2=.5+.8*(l2/(l1+l2))*cos(x)
xb=x2-.15*cos(x)
yb=y2-.15*sin(x)
th(x,y)=min(atan2(.5-x,y-.5),xdip)
@ meth=qualrk,dt=1,total=1000
done