Global fitting of two different function with shared parameters on two different data sets
22 次查看(过去 30 天)
显示 更早的评论
I am trying to generate a script to fit two different (tediously long) functions that describes two different properties of a certain experimental object. The two functions shares six fitting paremeters and is a function of "T". I have two data sets for each of those respective functions and I am trying to global fit them.
I searched around Matlab answers and found a code that seemingly did what I wanted to do (https://www.mathworks.com/matlabcentral/answers/496168-fitting-2-data-sets-simultaneously-using-two-different-equations-with-some-shared-fit-parameters). And then I made the following code:
syms kB hhat AT1 dG
kB = 0.695034800;
hhat = 5.308959927e-12;
AT1 = 50;
dG = 800;
%Data sets
Adata = [0.48; 0.50; 0.52; 0.7; 0.75; 0.81; 0.82];
Bdata = [8.9e-4; 8.9e-4; 8.8e-4; 8.75e-4; 8.6e-4; 8.5e-4; 7.9e-4];
GFD = [Adata, Bdata];
T = (100:50:400); %T range
%Symbols
%X(1) parameter 1
%X(2) parameter 2
%X(3) parameter 3
%X(4) parameter 4
%X(5) parameter 5
%X(6) parameter 6
%Fitting function
GFF = @(X,T) [X(3)*(X(1)*((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)-dG)^2/(4*X(6)*kB*T)))+X(2)*(AT1+((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)-dG)^2/(4*X(6)*kB*T)))))/((AT1+((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)-dG)^2/(4*X(6)*kB*T))))*(X(3)+X(4)+((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)+dG)^2/(4*X(6)*kB*T))))-((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)+dG)^2/(4*X(6)*kB*T)))*((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)-dG)^2/(4*X(6)*kB*T)))), 2/(AT1+((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)-dG)^2/(4*X(6)*kB*T)))+X(3)+X(4)+((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)+dG)^2/(4*X(6)*kB*T)))-((AT1+((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)-dG)^2/(4*X(6)*kB*T)))-X(3)-X(4)-((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)+dG)^2/(4*X(6)*kB*T))))^2+4*((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)+dG)^2/(4*X(6)*kB*T)))*((2*pi/hhat)*X(5)*(4*pi*X(6)*kB*T)^(-1/2)*exp(-(X(6)-dG)^2/(4*X(6)*kB*T))))^(1/2))];
%Root Mean Squared
RMS = @(X) rms(GFD - GFF(X,T));
options = optimset('MaxFunEvals', 1000000, 'MaxIter',1000000, 'Display', 'off', 'TolX', 1e-5);
FIT = fminsearch(RMS,[0.9 0.5 400 400 1e-6 1500],options);
I have two problem here.
1) The stopping criteria (TolX) is different for two functions, but I don't know how to specify that in my code.
2) The bigger problem, is that the it returns an error, "Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'."
I am assuming there's a problem in the last fminsearch command with its compatibility with what I'm trying to do, but I have no idea what I need to do.
Could someone help, please? Thank you.
0 个评论
采纳的回答
Walter Roberson
2023-2-1
your T is a vector. Your function involves an expression of T, then ^(1/2) . With T being nonscalar, the ^ operator is the Matrix Power operator, so you are asking for the matrix square root. But matrix power only works for square matrices, not for vectors. You need the .^ operation
4 个评论
Torsten
2023-2-1
I called your objective function with your vector of initial values for the parameters and it could not be evaluated (see above).
RMS must return a scalar value that usually is the sum of squared differences between your measurement data and the fitted data,
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!