Hello there, I would appreciate your help with me on this. I am modeling a second order differential equation ( mass and spring ). The spring is nonlinear (k x[t]^1.5). NDSolve solves the system but when encounters complex solutions it stoppes which makes sense to me. I want to make a constraint or a condition by using WhenEvent function inside the NDSolve to set x[t] to zero everytime the solution becomes complex or to just take the positive real part of it and continue solving for the specified period of time of 10 seconds. I've trying with no success. Please see the code in this message and I am also attaching the file for you. I would highly appreciate your help. Thank you
values = {m1 -> 1, m2 -> 2, m3 -> 3, E1 -> 210, E2 -> 210,
E3 -> 210, \[Nu]1 -> 1/3, \[Nu]2 -> 1/3, \[Nu]3 -> 1/3,
R1 -> 349/10000, R2 -> 349/10000, R3 -> 349/10000};
IC = {x1[0] == 0, x1'[0] == 1};
k1 = (1 - \[Nu]1^2)/(\[Pi] E1) /. values;
k2 = (1 - \[Nu]2^2)/(\[Pi] E2) /. values;
K12 = 4/(3 \[Pi] (k1 + k2)) Sqrt[(R1 R2)/(R1 + R2)] /. values;
\[Delta]12 = x1[t] + R1 /. values;
F12 = K12 \[Delta]12^1.5;
EQ1 = m1 x1''[t] + K12 (x1[t])^(3/2) == 0 /. values;
eqn = NDSolve[{EQ1, IC} /. values, {x1[t],x1'[t]
}, {t, 0, 10}, Method -> "StiffnessSwitching"]
Plot[Evaluate[x1[t] /. eqn], {t, 0, 10}, GridLines -> Automatic,
PlotRange -> All]
Plot[Evaluate[x1'[t] /. eqn], {t, 0, 10}, GridLines -> Automatic,
PlotRange -> All]
Attachments: