I have a set of coupled differential equations of functions which evolve (increase) monotonically:

NDSolve[{a'[t]=...,b'[t]=...,c'[t]=..., a[0]=a0, b[0]=b0, c[0]=c0},{a,b,c},{t,0,10}, 
Method -> {"EventLocator", "Event" -> a[t] == 1, "EventAction" :-> Print[t,b[t],c[t]]}]

is giving me what I want for any particular choice of a0, b0, c0, i.e. the values of t (let's call it t-threshhold), b, c when a[t] = 1.

What I want to do is scan across a range of {amin, amax, astep}, {bmin, bmax, bstep}, {cmin, cmax, cstep} and store the results.

Eventually I would like to generate a table of a0, b0, c0, and t-threshhold values.

Any idea on how I could do this? I am essentially struggling with meaningfully storing the result of the WhenEvent condition, and with scanning across initial values in NDSolve. Note that there are poles in a, b, c depending on the initial values, I want the solver to ignore this (to give me the t-threshhold value and then stop calculation at the t=tpole before moving on to the next set of initial conditions)

  • 2
    $\begingroup$ Instead of printing the results, use Sow and Reap. For instance: replace your EventAction with "EventAction" :> Sow[{t, b[t], c[t]}], and add a Reap at the top, i.e. results = Reap@NDSolve[...]. Look up their usage in the docs to clarify, and see this tutorial: Collecting Expressions during Evaluation. $\endgroup$ – MarcoB Jun 10 '18 at 23:16
  • $\begingroup$ @MarcoB - I have been able to use Sow and Reap with chosen initial conditions, however, I am still struggling with automatically "scanning" across initial conditions from a list {{a0,b0,c0},{a1,b1,c1},...}. Any suggestions on that? ParametericNDSolve hasn't been working for me and I also have a problem with the poles, and how to define a separate WhenEvent to stop integration when they occur $\endgroup$ – SarahThompson Jun 11 '18 at 10:01
  • $\begingroup$ Sarah, you should be able to take Sow and Reap techniques from this question, and combine them with the pure-function approach I gave you in this answer to your previous similar question. It seems to me that the problem of mapping over a list of initial conditions is solved there. If not, please provide a specific example of what does not work (i.e. complete equations; it can be a made-up system, but something that we can run). $\endgroup$ – MarcoB Jun 11 '18 at 15:56

Your Answer

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

Browse other questions tagged or ask your own question.