# Subtracting the overlap of functions

Tags:
1. Nov 26, 2014

### 2thumbsGuy

I have a fun project I'm trying to do and it's been a good number of years since I did any math higher than algebra. As such, I don't know how to approach this and would like some pointers.

I am trying to understand how I can subtract one function from another ONLY where the two functions overlap. The first part is easy enough (algebra), but the caveat is challenging to my grey matter. Can anyone advise me on how to approach this?

Thank you,

2thumbs

2. Nov 26, 2014

### ShayanJ

If two functions overlap in some region, it means they're both non-zero in that region. And in the regions where there is no overlap between them, it means at least one of them is zero in that region.So when you write $f(x)-g(x)$, it only changes the value of the functions in the regions that they have overlap and so you don't have to do anything special, just subtract them!

3. Nov 26, 2014

### 2thumbsGuy

I didn't think it would be that simple... let me just do that and see what I come up with. Thanks!

4. Nov 26, 2014

### ShayanJ

Just one more point. If you write $f(x)-g(x)$, and then calculate it in a region where f(x)=0, although there is no overlap, g(x) will change because it gets multiplied by a minus sign. So a little modification to a simple subtraction is needed.

5. Nov 26, 2014

### 2thumbsGuy

OK, I find it to be desirable where f(x) >= 0 and g(x) >= 0, so how can I restrict the function to that range before performing the subtraction? Or is it specific to the function?

EDIT

Here are the graphs I came up with to evaluate your statement:

Graph 1 ( f(x) )
http://www.wolframalpha.com/input/?i=-x^4+3x

Graph 2 ( g(x) )
http://www.wolframalpha.com/input/?i=-x^2+4x

Graph 3 ( g(x) - f(x) )

You can see on graph 3 the function at the right goes happily off to infinity on the y axis. Obviously this is because f(x) goes off to negative infinity faster than g(x) goes to negative infinity, so when inverted, f(x) wins. But if I stop them at zero before the subtraction, then I get my tidy little graph... I think

Last edited: Nov 26, 2014
6. Jan 17, 2015

### Svein

It depends on what you are trying to do when they do not overlap. A sketch: Let A be the region where they overlap, define XA as 1 on A and 0 outside A. Then define f1 = f* XA and g1=g*XA. Now f1-g1 = f-g on A and 0 outside A.