Trying to: -1- define a function which takes a number [step 1], write to a file [step 2], runs an external bash script [step 3], read a text file and return the result as a number [step 4] -2- trying to optimise this function with NMinimize
Here is the code of the function:
f[x_] := CompoundExpression[SetDirectory["~/Desktop/test"];
Print[x]; (*this is for debugging*)
Export["in.data", N[x],
"Text"]; (*this saves the value x in a text file*)
Run["~/Desktop/test/run.sh"]; (*this runs a shell script which \
takes the text file,
read it and makes the square of the number in in,
a place holder for more to come*)
N[ToExpression[
Import["out.data"]]](*this reads the number from the script \
output and convert to number*) ]
If I use: f[10], all if fine. the result is 100.
However if I use:
NMinimize[{f[y], 0 < y < 10}, {y}, Method -> "SimulatedAnnealing"]
The results is nonsense as the function writes "y" in the first text file as symbolic form.
Any idea on how to make this work? Thanks G.