# Modelica and SIMULINK yield completely different results

I'm trying to simulate a 1D model of two bodies sliding on each other with a Coulomb friction in between. 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
//constants
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;
//variables
Real X1, X2, V1, V2, A1, A2, F1, F2, Ff12, Fs12;

initial equation
X1 = 0;
X2 = 0;

V1 = 0;
V2 = 0;

equation
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;

Fs12=(m2*F1-m1*F2)/(m1+m2);

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

end friction;


and this is the result for $x_1$ and $x_2$: and I modeled the exact same thing in SIMULINK (download the .slx model here) and there is a completely different result: 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.

• 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.
– BlaB
Nov 10 '17 at 12:47
• @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?
Nov 10 '17 at 12:54
• I do not know sorry, this is very software specific regretfully...
– BlaB
Nov 10 '17 at 13:14
• 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. Nov 10 '17 at 14:42
• Look at the software documentation. Nov 10 '17 at 16:53

Switch solver to CVODES or tighten the tolerance to 1e^-8. Performing one of those changes results in this: 