nlinfit with modelfun as an integral

조회 수: 3 (최근 30일)
Armantas
Armantas 2014년 7월 31일
댓글: Star Strider 2014년 8월 3일
Dear all,
I have discrete data A(x,y), which I want to fit by a specified function y=f(x). My function f(x) has the following restriction: df(x)/dlog(x) is equal to a sum of two Gaussians. df(x)/dlog(x) being the derivative of f(x) with respect to the argument log(x). Given this restriction f(x) can be expressed as an integral. This gives 6 fit parameters, namely: the heights of the Gaussians, their means and their standard deviations. I have gone this far:
par=[1e-9,1e-5,1,10000,1,1]; %initial Gaussian parameter guess
Integrand = @(x) ((par(3)/(par(5)*(2*pi)^0.5))*exp((-(log10(x)-log10(par(1))).^2)/(2*par(5)^2))+(par(4)/(par(6)*(2*pi)^0.5))*exp((-(log10(x)-log10(par(2))).^2)/(2*par(6)^2)))./(x*log(10)); %two gaussians
Integral = @(x) integral(Integrand,0,x);
nlinfit(A(:,1),A(:,2),Integral,par)
I however get the following error:
Error using nlinfit (line 142)
Error evaluating model function '@(x)integral(Integrand,0,x)'.
Caused by:
Error using @(x)integral(Integrand,0,x)
Too many input arguments.
How can I fix this? Thank you

채택된 답변

Star Strider
Star Strider 2014년 8월 1일
편집: Star Strider 2014년 8월 1일
There are a few problems I can see. There could be more, but this should get you started:
Add ‘par’ to the Integrand function arguments:
Integrand = @(par,x) ((par(3)/(par(5) ...
The Integral function then becomes:
Integral = @(par,x) integral(@(x) Integrand(par,x),0,x);
I suggest that you name your initial parameter estimates ‘par0’ (or something other than ‘par’) to avoid confusion:
par0 = [1e-9,1e-5,1,10000,1,1]; %initial Gaussian parameter guess;
est_par = nlinfit(A(:,1),A(:,2),Integral,par0)
The ‘est_par’ assignment are the parameters estimated by nlinfit.
I can’t test your code (so no guarantees), but these changes should at least allow it to run.
  댓글 수: 8
Armantas
Armantas 2014년 8월 3일
편집: Armantas 2014년 8월 3일
Yes, it turns out NaN values in my A(x,y) where causing the problem.
Thank you for all the info, it was very helpful! Now the script is up and running :)
Star Strider
Star Strider 2014년 8월 3일
My pleasure!
Yours is the most unusual curve-fitting design (with the integral) that I’ve thus far encountered, so I learned much from it. It is also interesting that The Statistics Toolbox function nlinfit could deal with the NaN values on its own.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by