Levenberg Marquardt Curve Fitting Algorithm
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Robert U
el 4 de Jul. de 2018
Editada: Robert U
el 4 de Jul. de 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 comentarios
Matt J
el 4 de Jul. de 2018
Editada: Matt J
el 4 de Jul. de 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 comentarios
norlaila mustakim
el 13 de Jun. de 2020
do you know how to do the code if the model function is nonlinear?
Ver también
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!