How to determine coefficients by fit for multiple series of data?

8 ビュー (過去 30 日間)
Benedikt
Benedikt 2022 年 5 月 26 日
コメント済み: Benedikt 2022 年 5 月 30 日
Hey there,
I've searched for a while but did not find the right thing for my problem. I have several series of experiments with different amount of data, which might be described by an equation with 2 coefficents. The equation is:
y(x) = a * D * x^2 + b * x
D is a fixed value for each series of experiments, a and b are the coefficients I want to fit.
As an example x, y and D have the following values for three series of experiments (each row is one experiment):
x = [2,4,6,NaN,NaN; 2,4,6,8,10; 2,4,6,8,NaN];
y = [3,5,7,NaN,NaN; 4,8,11,25,32; 7,10,15,17,NaN];
D = [3;5;7];
Now I want to calculate the coefficients a and b by the fitting tool box, but the tool box throws just all values of y in and does not seperate the three cases with different value of D.
Is there a way to tell this the toolbox? or alternatively to calculate the coefficents by code?
Many thanks in advance for any help and best regards,
Benedikt

採用された回答

Torsten
Torsten 2022 年 5 月 26 日
x = [2,4,6,NaN,NaN; 2,4,6,8,10; 2,4,6,8,NaN];
y = [3,5,7,NaN,NaN; 4,8,11,25,32; 7,10,15,17,NaN];
D = [3;5;7];
N = size(x, 1);
A = [];
b = [];
for K = 1:N
mask = ~(isnan(x(K,:)) | isnan(y(K,:)));
tx = x(K,mask).';
ty = y(K,mask).';
A = [A;D(K)*tx.^2,tx];
b = [b;ty];
end
ab = A\b
a = ab(1)
b = ab(2)
  1 件のコメント
Benedikt
Benedikt 2022 年 5 月 30 日
Hi Torsten,
thanks for the solution! this works fine for me!
Best regards,
Benedikt

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 26 日
x = [2,4,6,NaN,NaN; 2,4,6,8,10; 2,4,6,8,NaN];
y = [3,5,7,NaN,NaN; 4,8,11,25,32; 7,10,15,17,NaN];
D = [3;5;7];
N = size(x, 1);
ab = zeros(N, 2);
for K = 1 : N
mask = ~(isnan(x(K,:)) | isnan(y(K,:)));
tx = x(K,mask);
ty = y(K,mask);
ty2 = ty ./ tx; %now it is A*D*x + b
p = polyfit(tx(:), ty2(:), 1);
ab(K,1) = p(1)./D(K);
ab(K,2) = p(2);
end
ab
ab = 3×2
-0.0278 1.6389 0.0352 1.3742 -0.0295 3.6875
  1 件のコメント
Benedikt
Benedikt 2022 年 5 月 26 日
Hi Walter,
thank you for your solution!
But it is not exactly what I search for. I just want one value for each coefficient a and b over all series of experiments because I know that phyiscally all series of experiments are the same but with different input parameters, described by D, and different scope.
So I want to use the data of all the three series to get a more accurate value for a and b, as I calucalte them just by one series of experiments.
Best regards,
Benedikt

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFit Postprocessing についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by