I'm trying to simulate a 1D model of two bodies sliding on each other with a Coulomb friction in between.

enter image description here

As I have explained here I modeled the friction as :

  1. The force required to keep two bodies adhered $F_{a12}=\frac{m_2F_1-m_1F_2}{m_1+m_2}$
  2. kinetic friction force $F_{f_k12}=Sign\left(v_1-v_2\right)\mu_k F_{n12}$
  3. maximum static friction $F_{f_s12}=\mu_s F_{n12} $
  4. $F_{f12}=\left\{\begin{matrix} if \, v_1=v_2 \, and \, \left| F_{a12} \right|<F_{f_s12} \,\, then & F_{a12} \\ else & F_{f_k12} \end{matrix}\right.$

Considering the values as $\mu_s=0.3$, $\mu_k=0.2$, $F_{n12}=3$, $m_1=1$, $m_2=2$, $F_1=2\sin(5t)$, $F_2=2\sin(7t)$ I implemented the model in modelica language as:

model friction
  parameter Real muk = 0.2;
  parameter Real mus = 0.3;
  parameter Real m1 = 1.0;
  parameter Real m2 = 2.0;
  parameter Real Fn12 = 3.0;
  parameter Real absTol = 0.1;
  Real X1, X2, V1, V2, A1, A2, F1, F2, Ff12, Fs12;

initial equation
  X1 = 0;
  X2 = 0;

  V1 = 0;
  V2 = 0;

  F1 = 2*sin(5 * time);
  F2 = 2*sin(7 * time);

  V1 = der(X1);
  V2 = der(X2);

  A1 = der(V1);
  A2 = der(V2);

  m1 * A1 = F1 - Ff12;
  m2 * A2 = F2 + Ff12;


  if abs(V1 - V2) < absTol and abs(Fs12) < mus * Fn12 then
    Ff12 = muk * Fn12 * sign(V1 - V2);
  end if;

end friction;

and this is the result for $x_1$ and $x_2$:

enter image description here

and I modeled the exact same thing in SIMULINK (download the .slx model here) and there is a completely different result: enter image description here

Why am I getting two completely different results?! Am I doing a mistake in implementation or the difference is due to the different solvers these two programs use? Which one should I trust in that case?!

P.S. I just realized that there is something wrong with Wolfram SystemModeler solver. When I do the simulation in OponModelica the result is more similar.

  • 1
    $\begingroup$ Are you using the same time steps? I have a feeling your modelica model is overshooting due to a too large time step. Simulink uses ode45 I believe by default which has adaptative time stepping. $\endgroup$
    – BlaB
    Commented Nov 10, 2017 at 12:47
  • $\begingroup$ @BlaB I just used the default settings. how/where I can change the time step? and what value is compatible with the one in ode45? $\endgroup$
    – Foad
    Commented Nov 10, 2017 at 12:54
  • $\begingroup$ I do not know sorry, this is very software specific regretfully... $\endgroup$
    – BlaB
    Commented Nov 10, 2017 at 13:14
  • 4
    $\begingroup$ I would assume that this is user error far before assuming this is a software error. Make sure it's actually the same, and solve at low tolerances to make sure each integrator is fairly exact. $\endgroup$ Commented Nov 10, 2017 at 14:42
  • 4
    $\begingroup$ Look at the software documentation. $\endgroup$ Commented Nov 10, 2017 at 16:53

1 Answer 1


Switch solver to CVODES or tighten the tolerance to 1e^-8. enter image description here

Performing one of those changes results in this: enter image description here

  • 2
    $\begingroup$ Increasing the negative exponent is decreasing the tolerance. $\endgroup$ Commented Nov 13, 2017 at 15:29
  • $\begingroup$ Yeah probably would have been better to call it tightening the tolerance. $\endgroup$
    – jrhodin
    Commented Nov 13, 2017 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.