0
$\begingroup$

I have a sequence of expressions

1, x, x^2, ..., x^5 

I want to define a sequence of functions out of it, what should I do? Namely I want to define a vector of functions with elements: $$ f_1 = 1, f_2 = x, ..., f_6 = x^5 $$ Any help is appreciated.

$\endgroup$
2
  • 3
    $\begingroup$ just keep in mind that f_1=1,f_2=x,...,f_6=x^5 isn't maathematica syntax (or at least it's not what you want it to be) $\endgroup$ Commented Mar 25, 2013 at 13:18
  • $\begingroup$ One way to manage lists of functions and to create orthogonal bases of them is described in my answer at mathematica.stackexchange.com/questions/19492/…. That solution begins vectors = Function /@ Table[#^k, {k, 0, 6}], etc., which directly answers the present question. $\endgroup$ Commented Mar 25, 2013 at 13:25

1 Answer 1

4
$\begingroup$

Like this?:

Function[x, Evaluate[x^#]] & /@ Range[0, 5] (* {Function[x, 1], Function[x, x], Function[x, x^2], Function[x, x^3], Function[x, x^4], Function[x, x^5]} *) 

Depending on what you'd like to do, it may be better to define and use a single function:

Function[x, Evaluate[x^# & /@ Range[0, 5]]] (*Function[x, {1, x, x^2, x^3, x^4, x^5}]*) %[2] (*{1, 2, 4, 8, 16, 32}*) 
$\endgroup$
4
  • $\begingroup$ How can I use them later? I need to calculate an orthogonal basis out of this, can I let fun=Function[x, Evaluate[x^#]] & /@ Range[0, 5], and refer to its elements later as fun[i]? $\endgroup$ Commented Mar 25, 2013 at 13:06
  • $\begingroup$ @TongZhang, see the edit, if that does not help, it might want to rework the question a bit to help understand what it really is that you are looking for. $\endgroup$ Commented Mar 25, 2013 at 13:11
  • $\begingroup$ +1. B.t.w., Evaluate is not really necessary, except the very first function, and for that one only if you want x^0 to evaluate to 1 at definition time. $\endgroup$ Commented Mar 25, 2013 at 13:24
  • $\begingroup$ The first line of code is what was looking for. $\endgroup$ Commented Mar 25, 2013 at 13:40