In [1]:
%pylab inline
In [2]:
def p(t):
if t < t0 :
return 54*(t0-t)**2*t/t0**3
return 0.00
In [3]:
mass = 3.
k = 1200.
zeta = 0.10
wn =sqrt(k/mass)
wd = wn * sqrt(1.00-zeta**2)
damp = 2*zeta*mass*wn
t0 = 0.12
print mass, damp, k
print wn, wd
In [4]:
# time step duration
h = t0/30.
# we require the response from 0 to 6 s, it is convnient
# to define a slightly modified duration
duration = 10*t0 + h/2
# The constants used by the algorithm
k_ = k + 2*damp/h + 4*mass/h/h
cv = 2*damp + 4*mass/h
ca = 2*mass
# We'll use these three containers to store our results
x = [] ; v = [] ; t = []
In [5]:
T = 0.00
X = 0.00
V = 0.00
P = p(T)
A = (P - V*damp - X*k)/mass
In [6]:
while T < duration:
x.append(X) ; v.append(V) ; t.append(T)
# print "%6.3f %+12.10f %+12.10f" % (t, X, V)
T = T+h
Ph = p(T)
dp_ = (Ph-P) + cv*V + ca*A
dx = dp_/k_
dv = 2*dx/h - 2*V
X = X+dx ; V = V+dv
P = Ph ; A = (P - damp*V - k*X)/mass
In [7]:
plot(t, [1000*X for X in x]) ; xlim((0,10*t0)) ; xlabel('t/s') ; ylabel('x/mm') ; grid() ; xticks(linspace(0,10*t0,11));