. . . &
is a held expression. (Function
has attribute HoldAll
.)
Injector pattern to the rescue:
Range@3 /. i_Integer :> (a[[i]] Sin[#] &)
Replace[Range@3, i_ :> (a[[i]] Sin[#] &), 1]
Table[j /. i_ :> (a[[i]] Sin[#] &), {j, 3}]
Or using \[Function]
and Array
:
Array[i \[Function] (a[[i]] Sin[#] &), 3]
In this case you could do the replacement the other direction but you will need to hold i
to protect it from a global value:
Table[a[[i]] Sin[#] & /. HoldPattern[i] -> j, {j, 3}]
Or use Block
:
Block[{i},
Table[a[[i]] Sin[#] & /. i -> j, {j, 3}]
]
a
supposed to be? Do you need something like the result ofFunction[c, c Sin[#] &] /@ Range[3]
orTable[With[{cs = c}, cs Sin[#] &], {c, Range[3]}]
? $\endgroup$Range[3] /. i_Integer :> (a[[i]] Sin[#] &)
orArray[Function[x, a[[x]] Sin[#] &], {3}]
. $\endgroup$