2

Say I have a list of interpolating functions and scales and want to combine them in a new function as in

p1=Interpolation[{1,2,3,4}];p2=p1;funs={p1,p2};
scales={2,4};

Now I want to do something like Dot[funs,scales][x] but what I tried (Through, Through2 from an answer here) doesn't work.

Jim
  • 67
  • 7

2 Answers2

3
h[t_] := Dot[Through[{f, g}[t]], {2, 4}]

h[5.63]
(* result: 2 f[5.63] + 4 g[5.63] *)

(* or using Function *)
y = Function[{t}, Dot[Through[{f, g}[t]], {2, 4}]];
y[9.14]
(* result: 2 f[9.14] + 4 g[9.14] *)
flinty
  • 25,147
  • 2
  • 20
  • 86
2

Something like this?

funScale[a_] := Function[{x}, a #[x]] &
funSum[f1_, f2_] := f1[#] + f2[#] &
funDot[scales_, funs_] := Inner[funScale[#1][#2] &, scales, funs, funSum]

funDot[scales, funs][x] (* 6 InterpolatingFunction[{{1, 4}}, { 5, 3, 0, {4}, {4}, 0, 0, 0, 0, Automatic, {}, {}, False}, {{1, 2, 3, 4}}, {{1}, {2}, {3}, {4}}, {Automatic}][x] *)

But there is probably a better way using the functional capabilities of Mathematica.

Natas
  • 2,310
  • 4
  • 14