Levenberg Marquardt Curve Fitting Algorithm

29 Ansichten (letzte 30 Tage)
Jonathan Trueblood
Jonathan Trueblood am 3 Jul. 2018
Kommentiert: Matt J am 13 Jun. 2020
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!

Antworten (2)

Robert U
Robert U am 4 Jul. 2018
Bearbeitet: Robert U am 4 Jul. 2018
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 am 4 Jul. 2018
Bearbeitet: Matt J am 4 Jul. 2018
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 Kommentare
norlaila mustakim
norlaila mustakim am 13 Jun. 2020
do you know how to do the code if the model function is nonlinear?
Matt J
Matt J am 13 Jun. 2020
In that case, youwould indeed use lsqcurvefit or lsqnonlin.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by