I have some functions, that I cannot break down to a reasonable MWE, so I'm going to try for an abstract question without providing the code. If need be, I'll include the extra code.
I have some functions that do some stuff. They seem to work when executed directly. When I put them in a Plot
it's really slow, because function evaluations can be 1 second each. So I'm making a Table
of values for a ListLinePlot, which is quicker (I've tried PerformanceGoal
and Mesh
and they were all slow). My problem is that I get errors that I cannot reproduce directly/manually. One example is if I run the following code,
maxThresh[findQ2[6]]
I get,
0.172831
But if I run,
Table[maxThresh[findQ2[q1]], {q1, {6}}]
I get,
During evaluation of In[702]:= NMinimize::nrnum: The function value -0.00996218+0.113392 I is not a real number at {x} = {0.516997}. >>
and a whole bunch more of similar errors. So the direct evaluation worked and gave me the right numerical answer, and the Table
evaluation gives me an error. I was hoping to gain an understanding as to how these two things are at all different. Does Table
not simply loop over the values and substitute in for q1
? There is a subtlety here, because running that function with the value 6
works (btw, it works for most values, but 20% fail with errors like these, that I cannot reproduce if I just execute the function directly).
Still haven't got my head around Mathematica substitutions...
Table
effectively usesBlock
to localize values or variables."[documentation] $\endgroup$Table[maxThresh[findQ2[§q1]], {§q1, {6}}]
work? $\endgroup$q1
somewhere in your code, that is not localized to a function. By renaming you avoid that unwanted change of that globalq1
. $\endgroup$