How to determine coefficients by fit for multiple series of data?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Benedikt
am 26 Mai 2022
Kommentiert: Benedikt
am 30 Mai 2022
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:
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
0 Kommentare
Akzeptierte Antwort
Torsten
am 26 Mai 2022
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)
Weitere Antworten (1)
Walter Roberson
am 26 Mai 2022
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
Siehe auch
Kategorien
Mehr zu Fit Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!