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,


I get,


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...


closed as off-topic by Michael E2, Henrik Schumacher, m_goldberg, MarcoB, b3m2a1 Jan 19 '18 at 6:43

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Henrik Schumacher, m_goldberg, b3m2a1
  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Michael E2, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Possible source of the problem: "Table effectively uses Block to localize values or variables."[documentation] $\endgroup$ – Karsten 7. Sep 15 '16 at 18:03
  • $\begingroup$ Does Table[maxThresh[findQ2[§q1]], {§q1, {6}}] work? $\endgroup$ – Karsten 7. Sep 15 '16 at 18:05
  • $\begingroup$ @Karsten7. yes that works! What is this black magic you have introduced me to? $\endgroup$ – bjorne Sep 15 '16 at 18:06
  • 3
    $\begingroup$ You probably have a global q1 somewhere in your code, that is not localized to a function. By renaming you avoid that unwanted change of that global q1. $\endgroup$ – Karsten 7. Sep 15 '16 at 18:31
  • 1
    $\begingroup$ The discussion in (94061) might be useful. $\endgroup$ – WReach Sep 19 '16 at 13:55

Browse other questions tagged or ask your own question.