Skip to main content
Post Reopened by creidhne, user1066, cvgmt, Artes, Karsten7
added 518 characters in body
Source Link

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 InterpolatingFunctions 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.

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 InterpolatingFunctions are not evaluated at that point.

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 InterpolatingFunctions 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.

added 627 characters in body
Added to review
Source Link

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 InterpolatingFunctions are not evaluated at that point.

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!

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 InterpolatingFunctions are not evaluated at that point.

Post Closed as "Needs details or clarity" by MarcoB, bbgodfrey, user81355, creidhne, Bob Hanlon
added 1 character in body
Source Link

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 to {f[x1],f[x2],f[x3]}. Thanks!

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!

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!

Source Link
Loading