A list of functions in Mathematica?

1. Jul 9, 2008

Lojzek

I would like to define and plot a list of functions in Mathematica without
typing all them, but I can't find the solution.

Let's say that we want to plot x, x^2, ..., x^10 on interval [0,1].

This is what I tried:

funclist=Table[#^n&,(n,1,10)]
Plot[funclist[x],(x,0,1)]

This does not work: n appears in the list as a variable. How can I tell the program that
the current numerical value of n should be used for the power?

2. Jul 11, 2008

ice109

what the hell is #

funclist = Table[x^k, {k, 1, 10}]
Plot[funclist,{x,0,1}]

works exactly how you want it to

3. Jul 11, 2008

Lojzek

Characters # and & are used to define a function of any argument without naming the argument (it is called a "pure function").

Actually my first try was the same as your, but it does not work. funclist is assigned the right powers, but Plot reports "funclist is not a machine sized real number at..."

Funny, if I copy the output of the funclist assignment sentence into the Plot function, then it works. I don't understand why, since the list intended to be plotted should be the same in both cases.

4. Jul 11, 2008

alphysicist

Hi Lojzek,

For the specific example you mention, I would do this:

Code (Text):

funclist=Table[x^n,(n,1,10)]

Plot[Evaluate[funclist],(x,0,1)]

or another example:

Code (Text):

funclist=Table[Sin[n x],{n,1,5}]

Plot[Evaluate[funclist],{x,0,1}]