# Solving delayed differential equations with Mathematica

Attempting to solve a delayed differential equation with the given model below, which has the structure of h[x[t - 1]] - .88*x[t]. We have defined h[x_,t_] as a piecewise below, that gives the value 3.52 if x[t-1] is between 1 and 2, but gives 0 when not in that interval. When we run the entire code, it gives us error code "DSolve::bvnul: For some branches of the general solution, the given boundary conditions lead to an empty solution." We are trying to model this for t between [0,20] When we run the same code but with the structure x[t-1]-.88*x[t] we do not receive an error code. Please help.

h[x_, t_] :=
Piecewise[{{3.52, 1 <= x[t - 1] <= 2}, {0, x[t - 1] > 2}, {0,
x[t - 1] < 1}}];
model = h[x[t - 1]] - .88*x[t];
g[t_] := 2;
tMin = 0;
tMax = 20;
DiscontinuityTree[t0_, Tend_, delays_] :=
Module[{dt, next, ord}, ord[t_] := Infinity; ord[t0] = 0;
next[b_, order_, del_] := Map[dt[b, #, order, del] &, del];
dt[t_, {d_, nq_}, order_, del_] :=
Module[{b = t + d},
If[b <= Tend, o = order + Boole[! nq]; ord[b] = Min[ord[b], o];
Sow[{t -> b, d}]; next[b, o, del]]];
rules = Reap[next[t0, 0, delays]][[2, 1]];
rules = Tally[rules][[All, 1]]; f[x_?NumericQ] := {x, ord[x]};
f[a_ -> b_] := f[a] -> f[b];
rules[[All, 1]] = Map[f, rules[[All, 1]]]; rules]
tree = Tally[
DiscontinuityTree[0, 8, {{1, True}, {\[Pi], False}}]][[All, 1]]
IntegrateSmooth[rhs_, history_, delayvars_, pfun_,
dvars_, {t_, t0_, t1_}] :=
Module[{delayvals, dvt, tau, hrule, dvrule, dvrules, oderhs, ode,
init, sol}, dvt[tau_] = Map[#[tau] &, dvars];
hrule[pos_] :=
Thread[dvars -> Map[Function[Evaluate[{t}], #] &, history[[pos]]]];
dvrule[(dv_)[z_]] :=
Module[{delay, pos}, delay = t - z; pos = pfun[t0 - delay];
dv[z] -> (dv[z] /. hrule[pos])]; dvrules = Map[dvrule, delayvars];
oderhs = rhs /. dvrules; ode = Thread[D[dvt[t], t] == oderhs];
init = Thread[dvt[t0] == (dvt[t0] /. hrule[-1])];
sol = DSolve[{ode, init}, dvars, t];
If[Head[sol] === DSolve || Length[sol] == 0,
Message[DDESteps::stuck, ode, init]; Throw[\$Failed]];
dvt[t] /. First[sol]]; DDESteps::stuck = "Not Working";
sol = DDESteps[h[x[t - 1]] - .88*x[t], 2, x, {t, 0, 3}]

• Running this code, I receive no error messages, but neither do I receive a meaningful answer. IntegrateSmooth is not called, and DDESteps is not defined. – bbgodfrey Oct 8 '18 at 0:15
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – bbgodfrey Oct 8 '18 at 1:21
• First 2 line code: h[x_, t_] := Piecewise[{{3.52, 1 <= x[t - 1] <= 2}, {0, x[t - 1] > 2}, {0, x[t - 1] < 1}}]; model = h[x[t - 1]] - .88*x[t] they don't do anything ? It's not delayed differential equations, maybe you mean recurrence equation ? – Mariusz Iwaniuk Oct 8 '18 at 10:18