How to fit regression

3 ビュー (過去 30 日間)
John fredson
John fredson 2022 年 5 月 20 日
コメント済み: Bjorn Gustavsson 2022 年 5 月 20 日
I have a equation y = Ae^-Bx, how to polyfit it and find A and B?

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2022 年 5 月 20 日
This is not a polynomial, therefore you cannot use polyfit. You can seamlessly use any least-square fitting routine to fit your 2 parameters. For example something like this:
mod_fcn = @(pars,x) pars(1)*exp(-pars(2)*x); % Describes your model y = A*exp(-B*x)
err_fcn = @(pars,x,y,sigma_y,m_fcn) sum((y(:)-m_fcn(pars,x(:))).^2./sigma_y^2);% general sum-of-squares function
par0 = [1 1]; % initial guess
parbest = fminsearch(@(pars) err_fcn(pars,x,y,ones(size(y))),par0); % least-square fitting
You can sometimes get far better performance with lsqnonlin. Check the help and documentation for that function and fminsearch.
HTH
  2 件のコメント
John fredson
John fredson 2022 年 5 月 20 日
can use linear regression file?
Bjorn Gustavsson
Bjorn Gustavsson 2022 年 5 月 20 日
Yes, if you mean your topspin.txt file. Just use the time in the first column for x (or more neatly replace x with t in my code-snippet) and set y to the rotational speed in the second column.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by