1
$\begingroup$

Im trying to solve a system of ordinary differential equations with some delay. I defined an intermediate variable in order to organize the system and also avoid that the system compute the same expression several times. Here is an small example of my problem

if i try to solve this system like this

NDSolve[{x'[t] == - y[t - 1] + k[t], y'[t] == -k[t] + x[t - 1], 
         k[t] == x[t] + y[t], x[t /; t < 0] == 1, y[t /; t < 0] == 0, k[t /; t < 0] == 1}, 
        {x, y, k} , {t, 0, 3}]

it gives this message and also quits the kernel

But if I change k[t] by the value x[t]+y[t] it gives the solution without any problem

NDSolve[{x'[t] == - y[t - 1] + (x[t] + y[t]), 
         y'[t] == -(x[t] + y[t]) + x[t - 1], 
         x[t /; t < 0] == 1, y[t /; t < 0] == 0}, {x, y}, {t, 0, 3}]

Does anybody know why is this happening? I would be grateful for your help... Thanks in advance Luis

$\endgroup$

closed as off-topic by xzczd, corey979, Feyre, gwr, m_goldberg Feb 6 '17 at 15:58

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Which version are you using? In v9.0.1 NDSolve gives the desired solution in both cases. (Though a warning ivcon generated. ) $\endgroup$ – xzczd Jan 31 '17 at 3:39
  • 4
    $\begingroup$ I'm voting to close this question as off-topic because nobody is able to reproduce the issue mentioned by OP for so long. $\endgroup$ – xzczd Feb 6 '17 at 8:49
  • $\begingroup$ Are you still waiting for an answer? $\endgroup$ – zhk Feb 17 '17 at 8:01
3
$\begingroup$

One way to do it is to convert the algebraic equation k[t] == x[t] + y[t] to a DE k'[t] == x'[t] + y'[t].

sol = NDSolve[{x'[t] == -y[t - 1] + k[t], x[t /; t <= 0] == 1,
   y'[t] == -k[t] + x[t - 1], y[t /; t <= 0] == 0,
   k'[t] == x'[t] + y'[t], k[t /; t <= 0] == 1}, {x, y, k}, {t, 0, 3}];
Plot[Evaluate[{x[t], y[t], k[t]} /. sol], {t, 0, 3},PlotStyle -> {Thick}, Frame -> True]

enter image description here

Now we will compare the above solution with the one you got from direct substitution of k[t] in the system.

sol1 = NDSolve[{x'[t] == -y[t - 1] + (x[t] + y[t]), 
   y'[t] == -(x[t] + y[t]) + x[t - 1], x[t /; t < 0] == 1, 
   y[t /; t < 0] == 0}, {x, y}, {t, 0, 3}]
Show[Plot[Evaluate[{x[t], y[t]} /. sol], {t, 0, 3}, 
  PlotStyle -> {Directive[Red, Thick], Directive[Red, Thick]}, 
  Frame -> True], 
 Plot[Evaluate[{x[t], y[t]} /. sol1], {t, 0, 3}, 
  PlotStyle -> {Directive[Green, Dashed], Directive[Green, Dashed]}, 
  Frame -> True]]

enter image description here

$\endgroup$
  • $\begingroup$ Im using the version 11. In this version it does not give the solution in the second case, which is something rare that i can not understand. Thank you very much for your solution $\endgroup$ – Luis Jan 31 '17 at 19:07
  • $\begingroup$ @Luis, I am using the same MMA. Can you explain more? $\endgroup$ – zhk Jan 31 '17 at 19:10
  • $\begingroup$ @luis v11.0 or v11.0.1? And what's your OS? $\endgroup$ – xzczd Feb 3 '17 at 12:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.