How to subtract interpolating functions

Hi,

I’ve generated two, 2-dimensional interpolating functions nu1 and nu2, and I’d like to subtract them to generate a third function. This doesn’t work:

In[123]:= nudifference = nu1 - nu2

Out[123]=
InterpolatingFunction[{{-0.5, 0.5}, {0., 0.866025}}, <>] -
InterpolatingFunction[{{-0.5, 0.5}, {0., 0.866025}}, <>]

Does anyone know how to make a function that’s the difference of two interpolation functions?

Thanks!

Hi,

does this work for you?

(*Generate data*)
x = RandomReal[1, {100}]; y = RandomReal[1, {100}];

(*Interpolate*)
f = Interpolation[x]; g = Interpolation[y];

(*Define difference function*)
h = f[#] - g[#] &

(*Evaluate h*)
h[5]
(*Out:= -0.193709*)

(*Plot h*)

Plot[h[x],{x,1,100}]

If you are careful about it, you can even differentiate it (I used InterpolationOrder-> 2 for this):

Plot[h'[b], {b, 1, 100}]

Cheers,

Marco

Yes! That does it!

nudifference = nu1[#1, #2] - nu2[#1, #2] &

worked for me.

Thanks a lot, Marco!