Consider the system below:
Fig.1 - Mass, spring, damper and Coulomb frction (image courtesy of
Wikimedia).
with a dynamic equation of:
where Ff
is the Amontons-Columb friction defined as:
and consequently, the no-slip
condition is defined as
Following this example, I have a vague code in mind which I don't know how to complete:
from scipy.integrate import odeint
import numpy as np
m = 1.0
k = 2.0
c = 0.1
mus = 0.3
muk = 0.2
g = 9.8
vf = 0.01
def eq(X, t, Xi):
Ff = k * (Xi[0] - X[0]) + c * (Xi[1] - X[1]) # - m * dydt
if np.abs(X[1]) < vf and np.abs(Ff) < mus * m * g :
Ff = k * (Xi[0] - X[0]) + c * (Xi[1] - X[1]) # - m * dydt
else:
Ff = -np.sign(X[1]) * muk * m * g
pass
dxdt = X[1]
dydt = (k * (Xi[0] - X[0]) + c * (Xi[1] - X[1]) - Ff) / m
return [dxdt, dydt]
t = np.linspace(0, 10, 1000)
Xi0 = np.piecewise(t, [t < 1, t >= 1], [0, 1])
X0 = [0, 0]
sol = odeint(eq, X0, t)
where Xi0
is a step function. My main issue is that when I want to define Ff
it depends on dydt
which is to be defined later in that scope!
I would appreciate if you could help me know what is the most canonical way to numerically solve this system. Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…