Message Boards Message Boards

GROUPS:

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[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!

POSTED BY: Charles Rackson
2 Replies

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}]

enter image description here

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

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

enter image description here

Cheers,

Marco

POSTED BY: Marco Thiel

Yes! That does it!

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

worked for me.

Thanks a lot, Marco!

POSTED BY: Charles Rackson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract