Suppose I have a simple list, Range[4]. I apply a function to the members of this list, e.g. f[x_] = 1/x. With the following code I am getting what I expected
In[125]:= f[x_] = 1/x;
Range[4];
Map[f, Range[4]]
Out[127]= {1, 1/2, 1/3, 1/4}
But now I want to use an InputField for defining the function to be applied to the list Range[4]. I then use the following code:.
Panel[DynamicModule[{f = 1/x, f1},
Column[{InputField[Dynamic[f]], f1[x_] = Dynamic[f],
Map[f1, Range[4]]}]]]
Here I started with the function f =1/x, but I can change it in the input field. With the above code I get a panel containing the input box, the definition of the new function f1 to be applied to the list Range[4], and the final result. I had expected this to be {1, 1/2, 1/3,1/4}., but I am getting {1/x,1/x,1/x,1/x}. What am I doing wrong?