1

following this question of mine Conditional PlotStyle, I ran into another problem.

I fear it has to do with evaluation orders, as for example described in Table and Evaluation Order, but I am totally unable to understand the subtlety.

Even recreating a minimum working example proved trickie. The following is sufficient to trigger a problem (although not exactly the same I witness, I hope the roots are the same).

A function is defined

  f2[x_, y_] := x^2 - y

and another two, the first using using FindMinimum

 g[y_] := FindMinimum[f2[x, y], x]

 f3[z_, n_] := g[z/n][[1]]

Now if I use

  Plot[Table[f3[z, n], {n, 1, 10}], {z, 0, 0.3}]

everything runs fine.

Yet, if I do

   Plot[Evaluate@Table[f3[z, n], {n, 1, 10}], {z, 0, 0.3}]

I get minimisation errors. In my original case I do get a plot, albeit a wrong one, compared to the correct results I get before using Evaluate.

Thanks

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Smerdjakov
  • 775
  • 4
  • 13

1 Answers1

3

Change the definitions to

f2[x_?NumericQ, y_?NumericQ] := x^2 - y;
g[y_?NumericQ] := FindMinimum[f2[x, y], x][[1]]
f3[z_?NumericQ, n_?NumericQ] := g[z/n];

Now it works

  Plot[Evaluate@Table[f3[z, n], {n, 1, 10}], {z, 0, 0.3}]

Mathematica graphics

This makes it "see" these functions with numerical arguments only, not symbolic, and hence these functions are called when the arguments has been bounded to the numerical values, and not before.

Nasser
  • 143,286
  • 11
  • 154
  • 359