As the titles describes, I want to create a list of functions like the following, where the indices are not in the argument slots:
f1[x_]=a1*x;
f2[x_]=a2*x;
f3[x_]=a3*x;
...
fn[x_]=an*x;
This is my unsuccessful attempt:
ToExpression["f"<>ToString[k]][x_]=ToExpression["a"<>ToString[k]]*x
So how should the code be written?
SubValuesor just straight-upDownvalues. Anyway, something likef[k][x_] = a[k]*x. If you really feel the need, replaceToExpressionwithSymbol, but in general this type of thing is unnecessary and perhaps even detrimental. Just do my first suggestion. – march Feb 29 '16 at 04:32With[{idx = IntegerString[1]}, Set @@ Hold[Symbol["f" <> idx][x_], Symbol["a" <> idx] x]](I'm not posting this as an answer since I don't want to.) – J. M.'s missing motivation Feb 29 '16 at 04:36f[k][x_] = a[k]*xis better, at least far simpler. By the way, what are SubValues? I searched for the term in the Help documents but didn't find it. – User18 Feb 29 '16 at 05:09f6[x], for instance, the output is stillf6[x], instead ofa6*x. What's wrong? – User18 Feb 29 '16 at 05:20ClearAll["Global`*"]and try my snippet again. – J. M.'s missing motivation Feb 29 '16 at 05:24IntegerString[1]withIntegerString[6]. I thought it was sufficiently apparent, but I guess not. – J. M.'s missing motivation Feb 29 '16 at 06:04