Mathematica A list of functions in Mathematica?

AI Thread Summary
To define and plot a list of functions in Mathematica, the correct approach is to use the Table function to create a list of expressions. The initial attempt using a pure function with # and & did not work because it treated n as a variable rather than a numerical value. The successful method involves using Table[x^k, {k, 1, 10}] and then applying Plot[Evaluate[funclist], {x, 0, 1}] to ensure the expressions are evaluated correctly. This technique also applies to other functions, such as Sin[n x]. Understanding the use of Evaluate is crucial for proper plotting of function lists.
Lojzek
Messages
246
Reaction score
1
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?
 
Physics news on Phys.org
what the hell is #

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

works exactly how you want it to
 
ice109 said:
what the hell is #

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

works exactly how you want it to

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.
 
Hi Lojzek,

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

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

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

or another example:

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

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

Similar threads

Back
Top