How to improve the fitting result
Show older comments
Hellow, there!
I am doing a fitting using quite involved custom equation. The definition of the function is as below:
function bif = bifit(A,bix,a,x,e,k,T)
fun = @(bix,b,a,x,e,k,T) exp(-b.^2./(2.*a.^2)).*heaviside(bix-x-b-e).*exp(-(bix-x-b-e)./(k.*T));
bif = integral(@(b) fun(bix,b,a,x,e,k,T),-1,1,'ArrayValued',1).*A;
end
Also, the code for fitting is as below:
ft = fittype('bifit(A,bix,a,x,e,k,T)','problem',{'x','k','T'},'independent','e'...
,'coefficients',{'A','bix','a'});
fo = fitoptions(ft);
fo.StartPoint = [129400 5.98470 0.01219];
fo.Lower = [120000 5.90000 0.00800];
fo.Upper = [300000 6.10000 0.13000];
bi = fit(data_x,data_y,ft,fo,'problem',{3.0169,8.61773*10^-5,161})
bi_coeff = coeffvalues(bi)
plot(bi,data_x,data_y,'-'),legend('exp','bi','location','Northeast')
'data_x' & 'data_y'(429x1 double respectively) are both column vector type data imported from excel file.
'e'(429x1 double) is a number type array(or matrix) data also imported from excel file.
The problem is that the result of the fitting returns the plot as shown below, which clearly does not fit the data:

The fitting should be as shown below:

The coeffvalues() returns the coefficient values as below, but it should be 129406 5.98480 0.01220 for the fit to look like the plot right above.
bi_coeff =
1.0e+05 *
1.2018 0.0001 0.0000
Thus, I was thinking to get a better fitting, I might need to extend the significant digit, or to bounds the x-axis value.
Any advice to improve the result of the fitting? Thanks a lot in advance!
1 Comment
Wonkyung Choi
on 10 Feb 2021
Accepted Answer
More Answers (1)
Matt J
on 10 Feb 2021
0 votes
Discard the data corresponding to data_x>2.98. Clearly, you do not want that to participate in the fit.
2 Comments
Wonkyung Choi
on 10 Feb 2021
Edited: Wonkyung Choi
on 10 Feb 2021
Matt J
on 10 Feb 2021
Discard the data from the fit only
keep=data_x<2.98;
bi = fit(data_x(keep),data_y(keep),ft,fo,'problem',{3.0169,8.61773*10^-5,161});
plot(bi,data_x,data_y,'-'),legend('exp','bi','location','Northeast')
Categories
Find more on Elementary Math in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!