2
$\begingroup$

This question already has an answer here:

This sounds like a fairly trivial question, but I can't think of any way to solve it. I am doing an extensive parameter sampling where a set of ODEs is used together with NDSolve to find values of the dependent variables at certain time points. Yet, I am getting several different errors (e.g. convergence errors) when using certain parameters.

Thus, I would like to ask your help in getting a way to find which parameters yield the errors, not how to fix the errors themselves.

The algorithm uses the system of ODEs (with defined initial conditions) and defines the function to compute the concentrations at various time points. It is then used to do the parameter sampling

SysODEs={X'[t]==ba+k1 A - b1 X[t], Y'[t]==k2 X[t]-v1 Y[t]-k1,etc};

DFunction[{a1_,b1_,v1_,k1_},ba_]:=
    Block[{sol1,c1,c2},
    sol1=NDSolve[SysODEs/.k2->2,{X,Y},{t,0,300}];
    c1=X[100]/.sol1;
    c2=Y[300]/.sol1;
    {c1,c2}
    ]

SampleP=Flatten[
    Table[{h, j, k, l}, {h, 0, 5, 1}, {j, 0.1, 0.9, 0.1}, {k, 1,10, 1}, {l, 5, 10, 1}],3];

ParallelMap[DFunction[#, 0.1] &, SampleP]

Problem: I want to know which values of SampleP yield errors. Because my original functions SampleP, DFunction etc. are much more complex, I didn't include them in here (SampleP has size ~200 000 in my problem). Is there any way of doing it? I was thinking about some kind of Trace, but this will give me too much unneeded information.

Edit: I was searching and found this link with information about the functions MLCreateMark() and MLSeekMark() that are used in MathLink. Maybe this helps in finding something similar in Mathematica?

$\endgroup$

marked as duplicate by rcollyer, Oleksandr R., Sosi, rm -rf Jun 13 '13 at 1:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ How about ParallelMap[Check[DFunction[#, 0.1],errorWith[#]] &, SampleP] $\endgroup$ – Sjoerd C. de Vries Jun 12 '13 at 18:27
  • $\begingroup$ This was answered here. To make it work, I added vars = {a1, b1, v1, k1}; as another Block variable and ran Map[DFunction[#, 0.1] &, SampleP] // withTaggedMsg[vars]. At issue, a1, etc., are not the same variable as defined in your equation because function parameters effectively have Module scope, i.e. they're unique, so they're not replaced. Also, k1 is a function in the second equation. $\endgroup$ – rcollyer Jun 12 '13 at 19:38
  • 1
    $\begingroup$ As to how to rewrite this, I'd change DFunction to DFunction[vars:{_,_,_,_}, b_]:= Block[{a1, b1, v1, k1, ba}, {a1, b1, v1, k1, ba} = vars~Join~{b}; .... Then, a1, etc., are scoped correctly. $\endgroup$ – rcollyer Jun 12 '13 at 19:51
  • $\begingroup$ I am yet to try it out and see, but those suggestions seem great! @SjoerdC.deVries I tried something similar, but wasn't able to get it. Let me get on that tomorrow! $\endgroup$ – Sosi Jun 12 '13 at 22:27
  • $\begingroup$ @rcollyer thanks for the very nice tips. I had searched around and didn't find that post which is indeed similar. Either way, thanks! $\endgroup$ – Sosi Jun 12 '13 at 22:28

Browse other questions tagged or ask your own question.