Custom Fit Sometimes Work Sometimes Doesn't
Show older comments
Hello-
I'm trying to find two fitting coefficients of a custom fit function.
Fitting works sometimes with a nice fit,

but sometimes it doesn't work at all with the same code and data and the fitting result is just absurd.

Can anyone help and teach me why this happens and how I can fix it?
Here is my code of the fitting part.
V and beta are given constant. I'm finding fitting coefficients gamma and n with the given data of Survival (y value) and Tsup_del (x value).
Any comments would be appreciated.
Thanks!!
% Find gamma and n from the survival function
g = fittype( @(gamma, n, x) exp(-V/beta*gamma/(n+1)*x.^(n+1)) ); %define fitting function
myfit = fit(Tsup_del,Survival,g); %fit with data
gamma = myfit.gamma;
n = myfit.n;
Survival_fit = exp(-V/beta*gamma/(n+1).*Tsup_del.^(n+1));
figure()
plot(Tsup_del,Survival,'s')
hold on
plot(Tsup_del,Survival_fit,'-')
title('Survival function fitting')
xlabel(['Relative Supercooling Temperature, \DeltaT_{sup} [' char(176) 'C]'])
ylabel('Survival Function, \chi')
legend('data','fit')
txt = texlabel(['gamma = ' num2str(gamma)]);
text(17,0.5,txt)
txt2 = texlabel(['n = ' num2str(n)]);
text(17,0.4,txt2)
Accepted Answer
More Answers (1)
the cyclist
on 12 Nov 2021
0 votes
You say this is the "same code and data". So, what is different? Or are you literally running everything in exactly the same way, and you sometimes get the poor fit?
If it is the latter, then I would guess that the fitting algorithm has a random element to it (perhaps in the guess of the initial parameters). Sometimes, the fitting routine will then get stuck in a local minimum that seems like the best it can do, but it does not find the true global minimum.
Can you upload the data in a MAT file? You can use the paperclip icon in the INSERT section of the toolbar.
1 Comment
Youngsup Song
on 13 Nov 2021
Categories
Find more on Gamma Distribution 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!