I have a dataset with values of multiple curves. An example plot is shown below. I want to shift the curves (up/down) so that all curves overlap. This would mean the data points in each curve is scaled up/down by a factor. I am not sure how to frame this as a mathematical problem (to minimize the vertical distance between each pair of curves) and determine the scaling factor for each curve. I tried to start by computing the pair-wise distance matrix but I am not sure what to do next.
Suggestions will be really appreciated.
EDIT:
The following is a sample dataset which includes that datapoints corresponding to 5 curves and coordinate inputs are below
scale = 1.5;
x1 = [0,4,6,10,15,20]*scale;
y1 = [18,17.5,13,12,8,10];
x2 = [0,10.5,28]*scale;
y2= [18.2,10.6,10.3];
x3 = [0,4,6,10,15,20]*scale;
y3 = [18,13,15,12,11,9.6];
x4 = [9,17,28]*scale;
y4 = [5,5.5,7];
x5 = [1,10,20]*scale;
y5 = [3,0.8,2];
plot(x1,y1, '*-', x2, y2, '*-', x3, y3, '*-', x4, y4, '*-', x5, y5, '*-')
And the plot looks like below. I tried to do a piecewise interpolation using a linear approximation to find the function values. Since the curves don't have a common x, I am not sure how the target function has to be selected.
Suggestions will be really appreciated.
Also, I only want to scale the datapoints $$\tilde f_i(a) = a \cdot f_i$$
and do not want to shift it along the x-dimension (I'm not sure if b
$\tilde f_i(a,b) = a \cdot f_i$ + b shifts the function value along the x-dimension; may be I am wrong and b
shifts the function value in the y-direction). And I also prefer to define a tolerance window/interval $\epsilon$ (user-defined) above and below the target function which will allow scaling the other curves such that they don't completely overlap on the target curve.
EDIT2: I would like to ask for a suggestion. If I want to scale $f_i$ (move it a bit up) and also scale $g_i$ (move it a bit down) would it make sense if the objective function is expressed as $(a⋅fi − gi)^2 + (b.gi - fi)^2$. Basically, I want to try and move both the curves towards each other instead of moving one curve towards the other.
EDIT3: @Vladislav Gladkikh
I like this idea, this preserves the shape of all $x_k$'s i.e the trend of the $x_k$'s before and after shifting doesn't change and I find this great. Could you please add a pictorial explanation of the third point?
I think overall we do, $f(x_k) - \bar{f(x_k)} + \bar{g(x_k)}$ Here, f is the non-main curve and g is the main curve (i.e y values of the curves at the corresponding x values), and $\bar{f(x_k)}$ is the average.
Then shift all curves toward the main curve so that their averages coincide within the corresponding domain segments.
I think I am a bit confused here since we are subtracting/adding the mean the $\bar{f(x_k)}$'s/ $\bar{g(x_k)}$'s computed at the $x_k$'s in the entire domain. I am not sure if my interpretation of segment is wrong, please correct me if I am wrong.
Could you please clarify if we refer to a segment as the domain between any 2 points that lie on the curve xk, yk here. Could you please illustrate this in a figure, if possible?