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
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?
Laurens, i would try to avoid Map[ ] and use Table[ ] instead. In the input field you can enter something like x*x or Sin[x] or 1/x, this works for example:
Thank you Raspal for your quick answer. But I am afraid I have misled you by taking Range[4] as an example of an arbitrary list. By using this the use of Table works fine. But what about using an arbitrary list? For instance examplelist = {5,3,10,43,3,74,4}?
Thank you very much, Raspi and Neil, for your suggestions. But now I am stuck with the further use of the resulting list. It turns out that I get for its length the value 1. Also Total, Max, and ListPlot don’t give proper results. Here is the general setup of a bigger program in which I need the liitle unit that applies a function to a list::
In the bigger program the list of variables in the Dynamic mdoule will contain several dozens of variables. Everything works fine, but in some way I am not able to access the values of the arguments in newlist. You will see that newlist looks as it should be, but Length and Max give nonsense.
Is there a special trick to access the values in newlist?
I am sorry Neil. I had forgotten a trick you once taught me. Instead of newlist I should use Map[ff1, list]] to calculate Length, etc. So the following code does what i wanted:
I am now going to build this in in my bigger program. It is a bit more awkward than I had hoped for, but I am pretty sure that I will succeed. Thanks again!