# Narrowing the gap between two curves

I want to raise the lower graph toward the upper graph to make the points of the lower graph as close as possible to those of the upper graph, in other words, to make the graphs "match" as closely as possible.

Any idea of how to do this in mathematical way? I tried taking the means of both graph then translating the lower graph by the percentage difference of the means, but this doesn't give me what I want.

• I come up with an idea similar to Riemann integral, but it's only an idea. Let's call $f$ and $g$ the functions whose graps are the blue one and the red one, respectively. Divide the domain in $n$ intervals with the same lenght. In each one of those intervals, change the value of $f$ on all the interval to be the mean of the values of $g$ in the same interval. With this, $f$ will become a piecewise function, where in each interval is as closely as possible to the graph of $g$. Finally, let $n$ tend to $\infty$. Commented Mar 2, 2023 at 16:01
• I think this question is a bit underspecified. When you say translate, do you mean shift by a constant value? In this case, just add the minimum of the difference of the functions to the lower one. If that's not what you mean, then note that you could trivially just let the blue function be the red function, and they would match exactly, so you must want to preserve some features of the original function, what are those features? Commented Mar 2, 2023 at 16:15

## 1 Answer

I believe you want to vertically translate the blue curve such that the signed area between the two curves is zero. This is equivalent to translating the blue curve upwards by the average value of the difference between the two curves. To do this:

• if the red and blue curves respectively represent $$y=f(x)$$ and $$y=g(x)$$ and the horizontal interval of interest is $$[a,b],$$ then translate the blue curve upwards by $$\frac1{b-a}\int_a^b f(x)-g(x)\,\mathrm dx.\tag1$$

on the interval $$[2,4],$$ translating this blue curve upwards by $$0.5$$ units (obtained from evaluation $$(1)$$) gives the green curve, which is its closest "match" to this red curve.

Addendum

Thank you so much, @ryang! That worked perfectly. How would I change it from "units shifted" to percentage shifted?

• The resulting average percentage increase of $$g(x)$$ is $$\frac1{(b-a)^2}\int_a^bf(x)-g(x)\,\mathrm dx\int_a^b\frac1{|g(x)|}\,\mathrm dx.$$

In the above example, this equals $$59.3\%.$$

• Thank you so much, @ryang! That worked perfectly. How would I change it from "units shifted" to percentage shifted? So instead of saying 0.5 units, I would give a percent instead? After taking the integral of both functions, I found the percentage difference from that and divided by b-a, but after shifting the graph by the percent, it didn't seem to match up. Commented Mar 4, 2023 at 19:08
• You added 0.5 units to shift the graph up, which works just fine. But I am asking, is there a way to shift the graph of up by a percentage instead? Sorry - I am not very good at explaining what I mean.... Commented Mar 4, 2023 at 19:45
• Lets use your example above. In the second function you listed, let imagine we plot all of its points. Now we want to translate it 0.5 units. Is there a fixed % number that we could multiply to each y-value of the points where it would shift graph up 0.5 units? Commented Mar 4, 2023 at 22:00
• Thank you Ryang, however, the relative change is giving me different percentages for each different point. I need a fixed percentage to raise the graph by.... What am I doing wrong here? Commented Mar 4, 2023 at 22:27
• I'll need to test those other formulas in that answer in a bit.. Thank you for your help! Commented Mar 4, 2023 at 22:50