1
$\begingroup$

The output of a set of differential equations solved with NDSolve produces a series of curves and I need to obtain the spacing between these curves at a given level on the y axis. I use MeshFunctions and Mesh to produce points on the plot. I need to find out the {t,y} values of these points.

The nb is as follows:

eqns = {Table[y[i]'[t] == 15 - (Exp[i]*10*Exp[-2*t] + 3)*y[i][t], {i, 0, 3}],
  Table[y[i][0] == 5, {i, 0, 3}]};
sol = NDSolve[eqns, Table[y[i], {i, 0, 3}], {t, 10}];

Plot[Evaluate[Table[y[i][t], {i, 0, 3}] /. sol], {t, 0, 6}, 
 MeshFunctions -> {#2 - 3 &}, Mesh -> {{0}}];
$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You 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. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Mar 31 '15 at 20:56
0
$\begingroup$

If you want the two solutions for each i:

r = {};
eqns = {Table[y[i]'[t] == 15 - (Exp[i]*10*Exp[-2*t] + 3)*y[i][t], {i, 0, 3}], 
        Table[With[{ii = i}, {y[i][0] == 5, 
                             WhenEvent[y[ii][t] == 3, AppendTo[r, {ii, t}]]}], 
                                                                   {i, 0, 3}]};
sol = NDSolve[eqns, Table[y[i], {i, 0, 3}], {t, 10}];
r

(*
  {{0, 0.0605192},  {0, 1.00734}, 
   {1, 0.019865},   {1, 1.5086}, 
   {2, 0.00705075}, {2, 2.0086}, 
   {3, 0.00256151}, {3, 2.5086}}
*)

LogLogPlot[
 Evaluate[Table[y[i][t], {i, 0, 3}] /. sol], {t, 0.000001, 6}, 
 MeshFunctions -> {#2 - 3 &}, Mesh -> {{0}}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thank you, it worked. Idially, I would prefer only the points after the minimae. (i took latin a large number of years ago.) $\endgroup$ – Jean-Pierre Raynauld Mar 31 '15 at 22:12
0
$\begingroup$
Flatten[Table[NSolve[(y[i][t] /. sol) == 3, t], {i, 0, 3}], 2]

(* {t -> 1.00734, t -> 1.5086, t -> 2.0086, t -> 668.12} *)

$\endgroup$
  • $\begingroup$ Three first points are OK but last one is wrong (668,12). $\endgroup$ – Jean-Pierre Raynauld Mar 31 '15 at 22:19
  • $\begingroup$ @DavidG.Stork Sure? Try eqns = {Table[ y[i]'[t] == 15 - (Exp[i]*10*Exp[-2*t] + 3)*y[i][t], {i, 0, 3}], Table[y[i][0] == 5, {i, 0, 3}]};sol = NDSolve[eqns, Table[y[i], {i, 0, 3}], {t, 0, 700}];Plot[Evaluate[Table[y[i][t], {i, 0, 3}] /. sol], {t, 0, 700}, PlotRange -> {0, 6}] $\endgroup$ – Dr. belisarius Mar 31 '15 at 23:53
  • $\begingroup$ Ah.. the solution from the range {0, 10} in the problem does not extrapolate accurately to large $t$. Indeed if you force the solution range to be large, you get a (slightly) different solution. Fair enough. $\endgroup$ – David G. Stork Apr 1 '15 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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