Fitting an exponential using nlinfit

I am trying to fit an exponential fit to some data... I have tried using Nlinfit but don't seem to be getting anywhere
nlmodel=@(b,time_bbdom)b(1)+b(2)*exp(-b(3)*time_bbdom(:,1));
beta0=[0;1;0.1];
mdl=nlinfit(time_bbdom,lum_bbdom,nlmodel,beta0);
I think the problem is my starting conditions beta0... How do I choose these variables? the error i get is Error using nlinfit>checkFunVals (line 612) The function you provided as the MODELFUN input has returned Inf or NaN values.
Error in nlinfit>LMfit (line 559) if funValCheck && ~isfinite(sse), checkFunVals(r); end
Error in nlinfit (line 276) [beta,J,~,cause,fullr] = LMfit(X,yw, modelw,beta,options,verbose,maxiter); Can anyone point me in the right direction? I would have thought its quite easy but i am not finding the documentation particularly helpful....

 採用された回答

Star Strider
Star Strider 2015 年 11 月 13 日

1 投票

If the values of ‘time_bbdom(:,1)’ are large enough, the ‘exp(-b(3)*time_bbdom(:,1))’ term will be zero, causing the Inf error. Without knowing more, one way to avoid this could be to set the initial value of ‘b(3)’ to ‘max(time_bbdom(:,1))/10’ or some such. You may have to experiment to get the result you want.

7 件のコメント

Matthew
Matthew 2015 年 11 月 13 日
Ok thanks very much... just getting warnings now so thats some progress =] I will experiment a bit
Star Strider
Star Strider 2015 年 11 月 13 日
My pleasure.
What are the warnings?
Matthew
Matthew 2015 年 11 月 15 日
I am getting warnings about the jaconbian having values very close to zero
Star Strider
Star Strider 2015 年 11 月 15 日
No worries, unless the fit is not the best. A Jacobian with values close to zero means that nlinfit has encountered a minimum. This is good if the errors are low (because it means you have likely found the global minimum), but if the errors are higher than you would expect them to be at convergence, you may want to experiment with different initial parameter estimates. If you have the Global Optimization Toolbox, the simplest genetic algorithm implementation is the best way I know of to find the global minimum to your function. With noisy data, you likely cannot reduce the errors significantly even with the ‘correct’ parameter estimates.
Matthew
Matthew 2015 年 11 月 16 日
Hi Yes the fit is terrible ha.. I do have access to GOT but i have never used it. I will look into it. Thanks for your help.. Ill post back here if I run into anymore problems
Matthew
Matthew 2015 年 11 月 17 日
Ok so i am still struggling... I essentially want to fit an exponential decay with a variable constant added (like above) which will all be done in a loop over many files... so I can't really input the initial values manually.. The x values range from 0 to about 1...
What is the best way to go about doing this? I initially tried taking the log and fitting with polyfit (it worked well) but I need to include this free variable that adds to exponential (the b(1)) mentioned above...is there a way i can do this with polyfit for example?
Star Strider
Star Strider 2015 年 11 月 17 日
The easiest way I can think of to estimate ‘b(1)’ is to take the mean or max of your data. Experiment with both and use the one that works best.
I don’t have your data or the code you used to implement polyfit, so I can’t comment on them.

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2015 年 11 月 13 日

コメント済み:

2015 年 11 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by