# Differential equations: How do I solve a delay differential equation with 0-1 variables

How do I solve the following non-linear, delay-differential equations using Mathematica under the assumptions $$p(t) = 1 ,\; y(t) > k$$ $$p(t) = 0,\; y(t)<= \ k$$. $$\frac{dw}{dt} = \frac{1}{R(t)} - \frac{w(t)x(t)}{2R(t)}p(t-D),$$ $$\frac{dx}{dt} = \frac{g}{R(t)}(p(t-D)-x(t)),$$ $$\frac{dy}{dt} = N\frac{w(t)}{R(t)} - c$$ $$D = d + k/c,$$ $$R(t) = d + y(t)/c$$

$$g,N,c,d,k \; are \; constants$$

Below is the code I wrote for it. I'm getting some errors which are listed just after the code.

Cell1

Clear["Global*"];
w0 = 1500 * 8; x0 = 0; y0 = 0; p0 = 0;
g = 1/16; k = 65 * w0; c = 10000*10^6; d = 100 * 10^-6; n = 20;


Cell2

r[t] = y[t]/c + d;
D0 = k/c + d;
ics = {w[t /; t <= 0] == w0, x[t /; t <= 0] == x0,
y[t /; t <= 0] == y0, p[t /; t <= 0] == 0};
eqs = {w'[t] == 1/r[t] - (p[t - D0] (w[t] x[t]))/(2 r[t]),
x'[t] == (g (p[t - D0] - x[t]))/r[t],
y'[t] == n (w[t]/r[t] - c), p'[t] == 0,
WhenEvent[{y[t] > k, p[t] -> 1,"IntegrateEvent" -> True},
{y[t] < 0, y[t] -> 0, "IntegrateEvent" -> True};
If[y[t] < 0, y[t] -> 0];
If[y[t] <= k, p[t] -> 0]], ics};


Cell3

sol1 = NDSolve[
eqs, {w[t], x[t], y[t], w'[t], x'[t], y'[t]}, {t, 0, 3},
MaxSteps -> 100000];


Cell4

Plot[Evaluate[{w[t], x[t], y[t]} /. sol1], {t, 0, 3}]

-
First, do not use uppercase (esp. single-letter) names, which may well be already in use by the system. N , C` e.g. are protected symbols (see the help). –  Yves Klett Nov 27 '13 at 7:05
I just did the corrections, here the error message I'm getting when I try to run the code. NDSolve::underdet: There are more dependent variables, {p[t],w[t],x[t],y[t]}, than equations, so the system is underdetermined. >> –  theereechee Nov 27 '13 at 14:49
@Nasser, I have adjusted it the show the complete code. –  theereechee Nov 30 '13 at 0:01
There is no syntax error now. –  theereechee Nov 30 '13 at 0:21
@Nasser thanks, I'd do just that. –  theereechee Nov 30 '13 at 0:31