What is the most elegant way of mapping an array of functions to an array of arguments of the same length? In practice I want to map {f1,f2,f3}
and {x1,x2,x3}
to {f[x1],f[x2],f[x3]}
. Thanks!
EDIT
I should have mentioned that {f1,f2,f3}
are the solutions of a differential equation:
fsol[t_] = Table[First[f[t] /. NDSolve[{f''[t] + m^2 f[t] == 0,
f[0] == c[[i]], f'[0] == cp[[i]]}, f[t], {t,0,1}]], {i,1,3}]
Then the output is something like
{InterpolatingFunction[t],InterpolatingFunction[t],InterpolatingFunction[t]}
When I evaluate fsol[t]
for some numerical t
I get a numerical array as a result. With the proposed solutions the argument gets appended at the end, but the InterpolatingFunction
s are not evaluated at that point.
EDIT 2:
Here is a minimal working example:
c = {1, 2, 3};
fsol = Table[NDSolveValue[{f''[t] + f[t] == 0, f[0] == c[[i]], f'[0] == 0}, f, {t, 0, 5}], {i, 1, 3}]
xtest = {1, 2, 3};
Then MapThread[#1[#2] &, {fsol, xtest}]
indeed gives the desired result. The remaining question is, can the same be done with the derivative of fsol
? MapThread[#1[#2] &, {fsol', xtest}]
doesn't seem to work, since Mathematica doesn't interpret that as the derivative of the components of the array.
MapThread[#1[#2] &, {{f1, f2, f3}, {x1, x2, x3}}]
$\endgroup$InterpolatingFunctions
returned byNDSolve
. In that case you should probably have a look at the alternativeNDSolveValue
. $\endgroup$MapThread[#1'[#2] &, {fsol, xtest}]
? $\endgroup$