1
$\begingroup$

I am trying to numerically solve a simple delay ODE in mma for the first time. I think this is likely a simple fix.

I first tried to solve system as ordinary differential equation system for up to 𝑡=l. And then use these solutions as history functions for the delay differential equation system. I keep getting the error: NDSolve::dvnoarg The function na appears with no arguments

ClearAll["Global`*"]
c = 200; Q = 4; P = 1.92*10^-6; ea = 2.6*10^-6; ga = 
6.24*10^-8; l = 0.5; ba = 98; pr = 0.2;
sol0 = NDSolve[{
 r'[t] == pr (c - r[t]) - P r[t]/(Q + r[t]) (na[t] + ma[t]),
 na'[t] == P r[t]/(ea (Q + r[t])) na[t] - pr na[t] - ga 
 na[t] p[t],
 ma'[t] == ga na[t] p[t] - pr ma[t],
 p'[t] == -pr p[t] - p[t] ga na[t] ,
 r[0] == 1000, ma[0] == 0, na[0] == 100, p[0] == 1000},
 {r, na, ma, p}, {t, 0, l}][[1]];

sol = NDSolve[{
 r'[t] == pr (c - r[t]) - P r[t]/(Q + r[t]) (na[t] + ma[t]),
 na'[t] == P r[t]/(ea (Q + r[t])) na[t] - pr na[t] - ga 
 na[t] p[t],
 ma'[t] == ga na[t] p[t] - pr ma[t] - 
   Exp[-pr l] ga na[t - l] p[t - l],
 p'[t] == ba Exp[-pr l] ga na[t - l] p[t - l] - pr p[t] - 
   p[t] ga na[t] ,
 r[0] == 1000, na[t /; t <= l] == sol0[[2]], ma[0] == 0, 
 p[t /; t <= l] == sol0[[4]]},
{r, na, ma, p}, {t, 0, 100}][[1]];

Any suggestions are much appreciated.

$\endgroup$
5
  • 1
    $\begingroup$ You might look at sol0[[2]] and sol0[[4]]. You probably want (na[t] /. sol0), or to use NDSolveValue for sol0 (the first NDSolve call). $\endgroup$
    – Michael E2
    Commented Apr 14, 2019 at 15:12
  • $\begingroup$ Thanks, (na[t] /. sol0) worked. $\endgroup$ Commented Apr 14, 2019 at 23:22
  • $\begingroup$ BTW, what's the model? Looks like a nutrient-consumer-virus system. $\endgroup$
    – Chris K
    Commented Apr 15, 2019 at 7:39
  • $\begingroup$ You are correct @Chris K $\endgroup$ Commented Apr 15, 2019 at 14:26
  • $\begingroup$ Nice, pretty close to my own research. I added an "ecology" tag. Good luck. $\endgroup$
    – Chris K
    Commented Apr 15, 2019 at 14:44

1 Answer 1

5
$\begingroup$

I'm not sure the separate NDSolve to initialize the initial conditions is even necessary. If you just use your second NDSolve with the initial conditions of the first, it gives a warning NDSolve::ihist but seems to run:

sol = NDSolve[{
  r'[t] == pr (c - r[t]) - P r[t]/(Q + r[t]) (na[t] + ma[t]), 
  na'[t] == P r[t]/(ea (Q + r[t])) na[t] - pr na[t] - ga na[t] p[t], 
  ma'[t] == ga na[t] p[t] - pr ma[t] - Exp[-pr l] ga na[t - l] p[t - l], 
  p'[t] ==  ba Exp[-pr l] ga na[t - l] p[t - l] - pr p[t] - p[t] ga na[t], 
  r[0] == 1000, na[0] == 100, ma[0] == 0, p[0] == 1000},
  {r, na, ma, p}, {t, 0, 400}, AccuracyGoal -> 128][[1]];

LogPlot[Evaluate[{na[t], ma[t], p[t]} /. sol], {t, 0, 400}, 
 PlotRange -> All]

Mathematica graphics

However note that I had to really crank up AccuracyGoal due to the very low levels that na[t] reaches. Maybe other parameter values would be less violent.

$\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.