Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
3  
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) –  acl Mar 25 '13 at 13:18
    
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. –  whuber Mar 25 '13 at 13:25

1 Answer 1

up vote 4 down vote accepted

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}*)
share|improve this answer
    
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]? –  user6193 Mar 25 '13 at 13:06
    
@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. –  user21 Mar 25 '13 at 13:11
    
+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. –  Leonid Shifrin Mar 25 '13 at 13:24
    
The first line of code is what was looking for. –  user6193 Mar 25 '13 at 13:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.