Levenberg Marquardt Curve Fitting Algorithm

18 ビュー (過去 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 Center および File ExchangeGet 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