Mathematica: Plotting a module with FindRoot in it <p>I run into this problem occasionally, and I haven't found a way around it. It usually happens when I'm finding the root of an equation, and want to maximize/minimize/plot that root according to some parameter. So I try to wrap the the code in a module so it can all be executed with just an input number, but it won't work inside functions like Plot. For example:</p> <pre><code>f[din_] := Module[{d = din}, sol = NDSolve[{y'[x] == y[x], y[0] == 1}, y[x], {x, 0, 10}]; t1 = Flatten[FindRoot[y[x] - d /. sol, {x, 1}]]; x /. t1 ] f[2] f[2.5] f[3] Plot[f[x], {x, 2, 3}] </code></pre> <p>The calls to f with a number all work as expected, but the f in the Plot function seems to be evaluated with the symbol 'x' - or something and just gives a lot of error text.</p> <p>Any way around this?</p> <p>Looking around the forums I found some suggestions for similar problems - like making the definition like this:</p> <pre><code> f[din_?NumericQ]:= </code></pre> <p>and I tried everything I could but nothing seems to make a difference. I'm using Mathematica 8.0</p>