# How to subtract interpolating functions

Posted 8 years ago
7372 Views
|
2 Replies
|
4 Total Likes
|
 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:= nudifference = nu1 - nu2Out= 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!
2 Replies
Sort By:
Posted 8 years ago
 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 (*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
Posted 8 years ago
 Yes! That does it! nudifference = nu1[#1, #2] - nu2[#1, #2] & worked for me. Thanks a lot, Marco!