2
$\begingroup$

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.

$\endgroup$
0

2 Answers 2

3
$\begingroup$
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] *)
$\endgroup$
1
  • $\begingroup$ Thanks, had the Dot and Through in the wrong order... $\endgroup$
    – Jim
    Jun 29, 2020 at 12:32
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.