Levenberg Marquardt Curve Fitting Algorithm
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposte (2)
Robert U
il 4 Lug 2018
Modificato: Robert U
il 4 Lug 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
0 Commenti
Matt J
il 4 Lug 2018
Modificato: Matt J
il 4 Lug 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 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with Curve Fitting Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!