# How generalize this concrete definition to arbitrarily many functions?

Posted 10 years ago
5519 Views
|
9 Replies
|
2 Total Likes
|
 Hello everybody,I'd like to define a function (let's call it »listoffunctions«), where I have to write only once the argument.That is: The aim is to write: listoffunctions[f1, f2, f3, ...] with arbitrary many functions, that can be evaluated at a point »x« and that gives as result {f1, f2, f3, ... }.In the attached notes I've managed to define such a function, but only for a fixed number of functions:listoffunctions = Function[{a, b, c, d}, Function[x, {a[x], b[x], c[x], d[x]}]];listoffunctions [e, f, g, h][x]Can you help me to generalize this definition?Best regards and thanks,Josip
9 Replies
Sort By:
Posted 10 years ago
 Thank you, again!
Posted 10 years ago
 lf2[function__][x__] := Through[{function}[x]]lf2[Power, Rational, Complex][2, 3]{8, 2/3, 2 + 3 I}Note the double underscore after function and x to match with multiple arguments
Posted 10 years ago
 Hello again,A problem occurs, if one puts in two or more variables.(e.g. for Power, Rational, Complex, Times, Plus,...)It works fine inside »Through«:Through[{Power, Rational, Complex}[2, 3]]Through[{Times, Plus}[1, 2, 3]]But within the new defined »lf« it doesn't worklf2[function_][x_] := Through[{function}[x]]lf2[Power, Rational, Complex][2, 3]lf2[Times, Plus][1, 2, 3]Can this be fixed somehow, so you can use arbitrary many variables?
Anonymous User
Anonymous User
Posted 10 years ago
 I've adapted it a little, so one doesn't need a list as variable, but can directly write the entries:lf2[function_][x_] := Through[{function}[x]]lf2[Cos, Sin][-Pi]{-1,0}
Posted 10 years ago
 Thank you. That's fantastic!
Posted 10 years ago
 @ Frank:  Thank you for your suggestion, Frank, but your definition does not work, if you try to evaluate lf[{Cos, Sin}] .@ Michael: It is very similar to the Function through. The only difference I'm aiming at is to uncouple it from the variable. lf2 = Function[{a, b, c, d}, Function[x, Through[{a, b, c, d}[x]]]]Here again I have the problem that the definition works only for a fixed number of function.»Through« has the disatvantage, that it can't be used inside a »Composition«, while »lf« works: e.g.: Composition[f, lf2[a, b, c, d], h][x]for suitable »f« and »h«.But the problem remains to generalizing the definition to arbitrary many functions.
Posted 10 years ago
 lf[function_List][x_] := Through[function[x]]lf[{Cos, Sin}]{1, 0}
Posted 10 years ago
 I'm probably missing something but the function you want sounds like Through:Through[{f1, f2, f3, f4}[x]](* Out[]= {f1[x], f2[x], f3[x], f4[x]} *)Or perhaps you're writing your own version as an exercise?
Posted 10 years ago
 lf[functionsofx_List][xx_] := functionsofx /. x -> xxlf[{x^2, x^3}]{4, 8}