I was hoping to be able to use MMA's minimization power to work with an external process. I want to minimize the function 'TryThisNumber[x_]' which sends the value of x to something external and gets back a result from that external object. I want to find the number which minimizes the returned result. But ... I can only talk to the external process using strings. So, assume I have a function SendNumberToProcess[m_String] which does the actual communication with the process, I try:
TryThisNumber[x_]:= ToExpression[SendNumberToProcess[ToString[x]]];
and then,
FindMinimum[{TryThisNumber[a],0<a<10},{a}];
The problem is that ToString[x] in the above is just evaluating to the symbol, a, not a numerical value, and thus I'm not actually able to send a number to the external process. Any ideas?
Update. Presumably the problem is that FindMinimum has the HoldAll attribute, but this attempt doesn't work either:
TryThisNumber[x_]:= ToExpression[SendNumberToProcess[ToString[Evaluate[x]]]];
TryThisNumber[x_?NumericQ] := (* stuff *)? – J. M.♦ Sep 21 '12 at 16:26NumericQ[]in your new definition... – J. M.♦ Sep 21 '12 at 16:37_?NumericQin the definition. – J. M.♦ Sep 22 '12 at 8:41