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)

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 11월 13일
편집: Cris LaPierre 2021년 11월 13일

0 개 추천

The initial guess or starting oint for the coefficients often is a random guess by default. I would suggest trying to specify a startpoint for the coefficients. These often do not have to be particularly close to the final coefficients. What it does is create a fixed starting point that can help avoid getting incorrect fits or inconsistent results.
Here's how I might modify your fit code. Try adjusting the startpoint values until your code's output is consistent.
myfit = fit(Tsup_del,Survival,g,'StartPoint',[0.1 10]);
See this example on the fit documentation page.

댓글 수: 1

thanks much! Setting a startpoint resolved the issue!!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
the cyclist 2021년 11월 12일

0 개 추천

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

yes, I was running everything in excatly the same way.
the problem was the starting point! Cris' script worked perfectly.
thanks!!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Descriptive Statistics and Insights에 대해 자세히 알아보기

태그

질문:

2021년 11월 12일

편집:

2021년 11월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by