I want to solve the delay differential equation given by

x'(t)=1-x(t)-x(t+2) if 0<= t <=2
      1-x(t)        if 2<  t <=4,

where x(4)=0 in Mathematica. I have already solved by hand and I obtained the solution

x(t)=e^(2-t)*(t-1-e^2) if 0<= t <=2
     1-e^(4-t)         if 2<  t <=4.

I used the following code


and I obtained the solution

x2[t]=1-e^(4-t) for 2 < t <= 4. After I used the code


and I obtained the message "Part 1 of {} does not exist." Can somebody help me? I don't know why I don't obtain the solution that I obtained solving by hand.


Thank you so much! In this form it results :) I also tried to compute using a piecewise function, but I didn't have success, too.

More one question... I want to derivate the function

H(u)=-u^2-y^2 + u*eta[t+1] if 0<= t <=3 and H(u)=-u^2 if 3<  t <=4

in order to u and solving this derivative equal to zero, using the following code:

eta[t_]:=Piecewise[{{E^(2-t)*(-1-E^2+t),0 <= t <= 2},{1-E^(4-t),2 < t <= 4}}]

H[u_] := Piecewise[{{-u^2 - y^2 + u*eta[t+1], 0 <= t <= 3}, {-u^2, 3 < t <= 4}}]

uS = D[H[u], u]

uSS = Reduce[uS == 0, u]

I want so save the output of uSS as a function u(t). How I can do this without using the archaic form given by

u[t_] = Piecewise[{{uSS[[1, 2, 2]], uSS[[1, 1]]}, {uSS[[2, 2, 2]], uSS[[2, 1]]}, {uSS[[3, 2, 2]], uSS[[3, 1]]}}]


Thanks again!

  • $\begingroup$ I wonder if DSolve can handle the delay actually coming from the "future" (t+2) instead of the past. Have you tried reversing t in your system? $\endgroup$
    – Chris K
    Commented Feb 26, 2017 at 19:26
  • $\begingroup$ I tried it with the past, it gives an output but still with the same error msg and a missing part. $\endgroup$
    – zhk
    Commented Feb 27, 2017 at 5:30
  • 1
    $\begingroup$ Please do not ask questions in 'answers' place. Please take an effort to format your edits ('?' button on the top right corner). Do not ask multiple questions at once and if you want some quick, small adjustment, make sure it is clear. $\endgroup$
    – Kuba
    Commented Feb 28, 2017 at 12:52

2 Answers 2


As per my comment, I defined a new "time" variable $\tau=4-t$ and substituted it along with $dt=-d\tau$ to get an equivalent "forward time" system $$dx/d\tau=\{x(\tau)-1,\tau<2; x(\tau)+x(\tau-2)-1,\tau>2\}$$ $$x(\tau=0)=0$$

Then DSolve works fine, following OP's approach:

DSolve[{x'[τ] == x[τ] - 1, x[0] == 0}, x, {τ, 0, 2}]
(* {{x -> Function[{τ}, 1 - E^τ]}} *)

sol = DSolve[{x'[τ] == x[τ] + x[τ - 2] - 1, x[τ /; τ < 2] == 1 - E^τ}, x,
  {τ, 2, 4}][[1]];
Simplify[x[τ] /. sol /. τ -> 4 - t]

Mathematica graphics

It would be nice to automate this transformation and to only use one DSolve on a Piecewise-defined function, but I couldn't get those to work.


Yes, the problem is in the x11[t+2] part of the expression in the first equation shown. Consider this simpler DE to solve:


It returns the error message

DSolve::litarg: To avoid possible ambiguity, the arguments of the dependent variable in {(x3^\[Prime])[t]==1-x3[2+t]} should literally match the independent variables.

The problem appears to be not formulated properly.

Also, substituting the answer given for the first eqn, obtained by hand, back into the first eqn doesn’t check.


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.