Question: Is it possible to create an array of functions?

If I have some similar functions, say sin(x), sin(2x)..., what approach is better:

f(i,x):=(i,x)->sin(i*x)

or

f[i](x):=x->sin(i*x)

?

Or maybe there is another way?

The second one seems more natural for me but  I've stucked with an error:

 

divide5.mw
 

NULLNULL

restart; divide5 := proc (f) local x, r; r := unapply((1/5)*f(x), x); eval(r) end proc; f := proc (x) options operator, arrow; x^2 end proc; f := divide5(f); f(3)

9/5

(1)

restart; divide5 := proc (f) local i, x, r; r := unapply((1/5)*f(i, x), i, x); eval(r) end proc; f := proc (i, x) options operator, arrow; x^2+i end proc; f := divide5(f); f(5, 3)

14/5

(2)

restart; divide5 := proc (f) local x, r; r := unapply((1/5)*f(x), x); eval(r) end proc; f[i] := proc (x) options operator, arrow; x^2+i end proc; f[5] := divide5(f[5]); f[5](3)

Error, (in f[5]) too many levels of recursion

 

NULL


 

Download divide5.mw

 


What's the matter?

Thank you for your answers.

 

Please Wait...