I have a dataset with values of multiple curves. An example plot is shown below. I want to scale the curves so that all curves overlap or get closer to the target curve. The following is the plot of a sample dataset
I want to scale the function values in the curves so that all curves overlap. Say, green curve is the target (g) and I want to move the other curves (f) towards target curve by scaling (scale facotor is a).
The function that I want to minimize is:
Expected result:
Data:
data = {{{157, 60}, {140, 57}, {121, 52}, {103, 47}, {86, 39}, {67, 28}, {50,21}, {32, 15}}, {{159, 70}, {140, 67}, {122, 63}, {105, 58}, {85, 45}, {68, 42}, {50, 34}, {33, 29}}, {{157, 74}, {140, 71}, {121, 70}, {105, 65}, {86, 55}, {69, 52}, {52, 43}, {32, 37}}, {{158, 100}, {141, 100}, {123, 95}, {105, 90}, {88, 78}, {69, 72}, {51, 57}, {33, 46}}, {{160, 143}, {140, 146}, {123, 146}, {105, 145}, {86, 136}, {70, 121}, {51, 97}, {34, 60}}}
Could someone please help me with the function that has to be used for solving this problem in MATLAB ?

 채택된 답변

Torsten
Torsten 2022년 7월 4일
편집: Torsten 2022년 7월 4일

0 개 추천

Differentiating with respect to a, setting the derivative to 0 and solving for "a" gives
a = sum_i (f_i*g_i) / sum_i (f_i^2)
I leave it to you to insert the data points.

댓글 수: 3

Deepa Maheshvare
Deepa Maheshvare 2022년 7월 6일
Thank you, this helps.
Could you please give suggestions on how this scale factor `a`can be determined if one wants to minimize the absolute error instead of the squared error?
Torsten
Torsten 2022년 7월 6일
편집: Torsten 2022년 7월 6일
What is the "absolute error" ?
sum_i abs(a*f_i - g_i)
?
If this is the case, use "linprog" to solve
min: sum_i u_i
s.c.
f_i * a - u_i <= g_i
-f_i * a - u_i <= -g_i
with unknowns a and u_i (i=1,...,number of data points).
Thanks so much. Yes, I mean sum_i abs(a*f_i - g_i)
% Loss Function (absolute error loss)
%% input curves
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];
%% y2 is the target function and y1 is the function to be shifted
f = y1;
g = interp1(x2,y2,x1);
%% linprog inputs
% x = linprog(f,A,b)
% i = 1:length(x1)
A = [fi - 1; -fi -1];
x = [a ui];
b = [gi -gi];
% obj = sum_i u_i (function to minimize)
%% solve system
I am not sure how to set this up in MATLAB's linprog
Could you please help?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 7월 4일

댓글:

2022년 7월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by