Levenberg Marquardt Curve Fitting Algorithm

조회 수: 20 (최근 30일)
Jonathan Trueblood
Jonathan Trueblood 2018년 7월 3일
댓글: Matt J 2020년 6월 13일
I'd like to use the Levenberg Marquardt nonlinear curve fitting algorithm to fit some data. The function is user defined:
y = a*g(x)+b+c*x+d*x^2
g(x) is a constant as a function of x. It is a matrix that I already have defined. So I'm not sure how to load this into the custom equation. The second half of the equation (b+c*x+d*x^2) is just a polynomial.
I can't figure out at all how to do this and I've tried multiple add-ons. Thank you!

답변 (2개)

Robert U
Robert U 2018년 7월 4일
편집: Robert U 2018년 7월 4일
Hi Jonathan Trueblood,
Levenberg-Marquardt-Algorithm is built-in into lsqcurvefit(), Optimization Toolbox. You would have to define its use by setting options accordingly (cf. optimoptions()):
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt');
Then define your custom function in any way (anonymous, nested or external). Examples, on how to use lsqcurvefit() can be found in documentation.
You may define g(x) as a stand-alone function and plug it into another function:
g = @(x) x^2+x;
y = @(x) 5 * g(x) + 1;
y(1)
>> 11
The function handle y can now be used as function to be optimized if parameters have been set accordingly.
y = @(x,xdata) x(1).*g(xdata)+x(2)+x(3).*xdata+x(4)*xdata.^2;
Kind regards,
Robert

Matt J
Matt J 2018년 7월 4일
편집: Matt J 2018년 7월 4일
It is overkill to use Levenberg-Marquardt for a problem like this, where the model function is linear in the unknown parameters. Just use a linear solver,
gx=g(x); %the matrix you have
p=[gx(:), x(:).^(0:2)]\y(:);
[a,b,c,d] = deal(p(1), p(2), p(3), p(4));
  댓글 수: 2
norlaila mustakim
norlaila mustakim 2020년 6월 13일
do you know how to do the code if the model function is nonlinear?
Matt J
Matt J 2020년 6월 13일
In that case, youwould indeed use lsqcurvefit or lsqnonlin.

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

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by