When simulating a friction dynamic system, I have come to a problem when approaching steady-state.
In the example below, a box moves along a surface with a certain friction coefficient:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
G = 9.8
MU = 0.3
TIME_STEP = [0.1, 0.01, 0.001]
SIM_TIME = 10 # s
fig, ax = plt.subplots()
for time_step in TIME_STEP:
t = np.linspace(0, SIM_TIME, int(SIM_TIME/time_step))
speed = 10 # m/s
s = []
for i in t:
speed += -np.sign(speed)*G*MU*time_step
s.append(speed)
ax.plot(t, s, label = "Time step {:1.3f} s".format(time_step))
ax.set_xlabel('Time (s)')
ax.set_ylabel('Speed (m/s)')
ax.legend(loc='upper right')
Since the friction is only dependent on the speed unit vector, the system oscillates around the steady-state point instead of converging to 0. The oscillation vary depending on the time_step simulated, but it is there always.
The difficulty is that in the real system, the steady-state point is not known, so approaches like making the speed equal to zero when crossing the steady-state point are not applicable.
Is there a way for this to be coded in order to avoid those steady-state oscillations, and without loosing physical integrity?
EDIT
The equations for the given system are:
$v_{0}=10$
$\dot{v}=-\frac{v}{\left | v \right |}\cdot g\cdot \mu $
scipy.integrate.solve_ivp
has anevent
option to do this $\endgroup$ – xdze2 Jul 31 '19 at 9:13