Clear["`*"]
P0 = 101300; c01 = 0.001*32.5; c06 = 13 Degree; c07 = 0 Degree; c18 =
0.001*25;
Z1 = 60/3000; N1 = 2*Pi/Z1; M2 = 0.001*60; L0 = 0.001*20; Tplot =
10*Z1; f20 = 1; f21 = 30;
x1[t_?NumericQ] := c01*Tan[ArcTan[Tan[c06]*Cos[N1*t]]]
d20 = P0*Pi*(0.5*c18)^2*(L0/(#1 - #2) - 1) &;
d2[f_, x1_, x11_, x111_, x2_, x22_, x222_] :=
If[Abs[x11 - x22] < 10^-6,
If[Abs[M2*x111 - Evaluate@Apply[f, {x2, x1}]] <= f21, M2*x111,
Evaluate@Apply[f, {x2, x1}] + Sign[x111 - x222]*f21],
Evaluate@Apply[f, {x2, x1}] + f20*Sign[x11 - x22]];
eq = M2*x2''[t] ==
d2[d20, x1[t], x1'[t], x1''[t], x2[t], x2'[t], x2''[t]] -
M2*9.8*Sin[c07]
ini1 = x2[0] == L0 + (c01*Tan[ArcTan[Tan[c06]*Cos[N1*0]]])
ini2 = x2'[0] == -0.0001
s = NDSolve[{eq, ini1, ini2}, {x2[t], x2'[t], x2''[t]}, {t, 0, Tplot},
Method -> {"EquationSimplification" -> "Residual"}];
Plot[{x1[t], Evaluate[x2[t] /. s], 0.01*x1'[t],
0.01 Evaluate[x2'[t] /. s], -0.01*f20*
Sign[Evaluate[(x1'[t] - x2'[t]) /. s]],
0.001*Evaluate[
d2[d20, x1[t], x1'[t], x1''[t], x2[t], x2'[t], x2''[t]] /.
s]}, {t, 0, Tplot}, PlotRange -> All, AxesLabel -> {t, x2},
PlotLegends -> {"1位移", "2位移", "1速度*0.01", "2速度*0.01", "2摩擦力*0.01",
"2合力*0.001"},
PlotStyle -> {Blue, ColorData["HTML"]["CornflowerBlue"],
ColorData["HTML"]["DarkOrange"],
ColorData["HTML"]["Orange"], {Gray, Dashed},
ColorData["HTML"]["DarkGray"]}]
问题存在于d2函数里的Sign[x111 - x222]*f21部分,若去除该部分,可以正常求解,但加上之后提示NDSolve::tddisc: NDSolve cannot do a discontinuity replacement for event surfaces that depend only on time. 求解的结果也不对。考虑过用WhenEvent、设置NDSolve的method属性,由于能力有限,一直没能解决。有大神可以交流下吗?