Fitting multiple Datasets with shared and individual Parameters.

14 views (last 30 days)
Hello Matlab Community,
I wan't to fit Multiple Datasets to one Modellequation. Some Parameters are shared and should be fitted to all datasets, while there are some parameters which should be fitted individual for each dataset. I think i found a code in this board which can help me do that, but i do not understand how my raw data has to be supplied. In detail, how should my .xls-File look like? My xdata will be the Time and the y data will be the Mass. Here is the code:
% function sharedparams
ds = dataset('xlsfile', 'Test.xlsx') ;
ds.dataset = nominal(ds.dataset);
% Initial estimates for [N, D, M_C11, M_C12, M_C21 and M_C22]
p0 = [120 , .01 , 100, 100, 100, 100];
% Estimate parameters
fn = @(p , f ) objFcn(p , f , ds.dataset) ;
% Function handle
lb = [100 , 0 , 0, 0, 0, 0]; ub = [180 , 0.3 , 300, 300, 300, 300]; options = optimoptions('lsqcurvefit'); options.TolFun = 1e-10;
pFit = lsqcurvefit(fn , p0 , ds.Frequency , ds.Magnitude,lb, ub, options);
assignin('base','pFit',pFit);
end
function yfit = objFcn(p , f, dataset)
N = p(1) ; % location-independent parameter 1
D = p(2) ; % location-independent parameter 2
M1 = p(3) ; % Location dependent parameter (C11)
M2 = p(4) ; % Location dependent parameter (C12)
M3 = p(5) ; % Location dependent parameter (C21)
M4 = p(6) ; % Location dependent parameter (C22)
f1 = 2*pi*f(dataset == 'A');
yfit_C11 = (0.0035*0.027*f1.^2*N^2)./(M1*sqrt((N^2-f1.^2).^2+(2*D*N*f1).^2));
f2 = 2*pi*f(dataset == 'B');
yfit_C12 = (0.0035*0.027*f2.^2*N^2)./(M2*sqrt((N^2-f2.^2).^2+(2*D*N*f2).^2));
f3 = 2*pi*f(dataset == 'C');
yfit_C21 = (0.0035*0.027*f3.^2*N^2)./(M3*sqrt((N^2-f3.^2).^2+(2*D*N*f3).^2));
f4 = 2*pi*f(dataset == 'D');
yfit_C22 = (0.0035*0.027*f4.^2*N^2)./(M4*sqrt((N^2-f4.^2).^2+(2*D*N*f4).^2));
% Combine prediction
yfit = [yfit_C11; yfit_C12; yfit_C21; yfit_C22] ;
end
P.S.: The parameters and Modell is not the one I am going to fit since my question is regarding the supplied raw data.
Thank you guys in advance!
Fabian

Answers (1)

Alex Sha
Alex Sha on 28 Apr 2019
Hi, Fabian Bienen, if possible please upload your data here, I may try to solve it.

Community Treasure Hunt

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

Start Hunting!