0
$\begingroup$

Consider some function

function[mass_,lifetime_]:=NDSolve[{equations[mass,lifetime], initialconditions},functions,{t,t0,tmax}]

Let us assume that there is some kind of numeric instability in this function related to the syntax I used. Namely, for some values of parameters (like mass = 0.05, lifetime = 0.03), it is evaluated without any problems (apart from some warnings which may be neglected), but for some very similar values (like mass = 0.05, lifetime = 0.0301) it returns an error like

NDSolve::mxst: Maximum number of 50000 steps reached at the point t ==

0.00521324.

I need to make a table

table = Flatten[Table[{mass,lifetime,function[mass,lifetime]},{mass,massvalues},{lifetime,lifetimevalues}],{2,1}]

Is it possible to re-define the table such that rows with the error will be marked somehow?

Like

tableModified = Flatten[Table[{mass,lifetime,label,function[mass,lifetime]},{mass,massvalues},{lifetime,lifetimevalues}],{2,1}]

for which label = 1 if the mentioned error has not occurred and label = 0 if the error has occurred?

$\endgroup$
2
$\begingroup$

Try to use Check. For example:

Check[{tmp1=SomeCode,1},{tmp1,0},MessageName];

$\endgroup$
2
  • $\begingroup$ Thank you. But will it work for arbitrary details of message (maximum number of steps reached at different times)? $\endgroup$ – John Taylor Nov 8 '20 at 10:07
  • $\begingroup$ @JohnTaylor If you want to check any message, you can omit the last argument of Check (that is, MessageName). $\endgroup$ – Wen Chern Nov 9 '20 at 12:27

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.