# Define linear combination of InterpolatingFunctions as new function

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.

## 2 Answers

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] *)

• Thanks, had the Dot and Through in the wrong order...
– Jim
Jun 29, 2020 at 12:32

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.