2
$\begingroup$

Using Sign(...)] in the formulation of my system of ODEs is causing an error that I don't know how to correct. If I use (...) in its place there isn't any problem!

ClearAll[x1, x2, x3];
c = 5;
k = 1;

r[t_] := Evaluate[2];
rdot[t_] := Evaluate[D[r[t], t]];
r2dot[t_] := Evaluate[D[r[t], {t, 2}]];

u[t_] := 1/
   b2[t]*(-(a21[t]*x1[t] + a22[t]*x2[t]) + 
     r2dot[t] - c (x3'[t] - rdot[t]) - 
     k*Sign[((x3'[t] - rdot[t]) + c (x3[t] - r[t]))]);

a11[t_] := -0.4683*Exp[-0.03955*t] - 5.787*Exp[-2.308*t];
a12[t_] := (-1.248*10^(-8)*t^4 + 2.863*10^(-6)*t^3 - 0.0001976*t^2 + 
     1.004*t + 1.112)/(t + 1.115);
a13[t_] := -1.771*Exp[-3.312*t] - 0.3232*Exp[-0.2442*t]
a21[t_] := 
  8.044*Sin[0.176*t + 0.8637] + 8.672*Sin[0.06238*t - 2.693] + 
    3.578*Sin[0.3067*t - 2.259] + 1.41*Sin[0.4156*t - 4.424];
a22[t_] := 
  0.1411*Sin[0.04112*t - 2.51] + 0.03332*Sin[0.1928*t - 5.057] + 
    0.01927*Sin[0.329*t - 2.967] + 0.01594*Sin[0.4339*t - 4.503];
b1[t_] := -0.3851*Exp[-3.171*t] - 0.06556*Exp[-0.2131*t];
b2[t_] := 
  1.295*Exp[-((t - 48.88)/6.474)] + 1.826*Exp[-((t - 6.799)/27.72)] + 
    1.283*Exp[-((t - 37.72)/13.11)];
sol = 
  First[
    NDSolve[{
      x1'[t] == a11[t]*x1[t] + a12[t]*x2[t] + a13[t]*x3[t] + b1[t]*u[t], 
      x2'[t] == a21[t]*x1[t] + a22[t]*x2[t] + b2[t]*u[t], 
      x3'[t] == x2[t], x1[0] == -2, x2[0] == 2, x3[0] == -4}, 
      {x1, x2, x3}, {t, 0, 1000}]];

Show[
  Plot[r[t], {t, 0, 50}, 
    PlotRange -> {{0, 30}, {-5, 5}}, 
    PlotStyle -> {Thick, Brown}], 
  Plot[Evaluate[{x1[t], x2[t], x3[t]} /. sol], {t, 0, 30}, 
    PlotStyle -> 
      {{Thick, Blue}, {Thick, Green, Dashed}, {Thick, Red, Dotted}}, 
    PlotRange -> {{0, 30}, {-5, 5}}]]

Error is:

NDSolve::tddisc: NDSolve cannot do a discontinuity replacement for event surfaces that depend only on time. >>

$\endgroup$
2
  • 1
    $\begingroup$ Do you think you could reduce your problem to a smaller example that exhibits the same behavior? It might attract more attention that way. $\endgroup$
    – MarcoB
    Commented Jul 6, 2015 at 0:44
  • $\begingroup$ Yes,i think it can be simplify. it was my my first problem in this site, i am a beginner!!! $\endgroup$
    – Farshid
    Commented Jul 6, 2015 at 8:48

1 Answer 1

2
$\begingroup$

Rewrite the following parts of your code in order to eliminate x2:

u[t_] := 1/ b2[t]*(-(a21[t]*x1[t] + a22[t]*x3'[t]) + r2dot[t] - 
          c (x3'[t] - rdot[t]) -  k*Sign[((x3'[t] - rdot[t]) + c (x3[t] - r[t]))]);

sol = First[NDSolve[{
     x1'[t]  == a11[t]*x1[t] + a12[t]*x3'[t] + a13[t]*x3[t] + b1[t]*u[t], 
     x3''[t] == a21[t]*x1[t] + a22[t]*x3'[t] +                b2[t]*u[t],
     x1[0]   == -2,
     x3'[0]  == 2,
     x3[0]   == -4},
    {x1, x3}, {t, 0, 1000}} ]];

Show[Plot[r[t], {t, 0, 50}, PlotRange -> {{0, 30}, {-5, 5}}, 
          PlotStyle -> {Thick, Brown}], 
    Plot[Evaluate[{x1[t], x3[t]} /. sol], {t, 0, 30}, 
          PlotStyle -> {{Thick, Blue}, {Thick, Green, Dashed}},
          PlotRange -> {{0, 30}, {-5, 5}}]]

Mathematica graphics

$\endgroup$

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.