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:
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}]
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.
Any way around this?
Looking around the forums I found some suggestions for similar problems - like making the definition like this:
f[din_?NumericQ]:=
and I tried everything I could but nothing seems to make a difference. I'm using Mathematica 8.0