Which curve fitting function do I need?

1 回表示 (過去 30 日間)
Omar Mian
Omar Mian 2011 年 9 月 20 日
I want to fit the following function to measured data in order to estimate R:
D = atan2(sin(H),R*cos(H))
I have measured H & D
H will be in the range -1.1*pi/2 to 1.1*pi/2
I expect R to be approximately +2
To visualize, see:
figure
H = [-1.1*pi/2:0.1:1.1*pi/2]';
R = 2;
D = atan2(sin(H),R*cos(H));
plot(H,D)
I don't know which curve-fitting function to use. I have access to both the curve-fitting and optimization toolboxes. Any advice would be much appreciated.
Thanks

採用された回答

bym
bym 2011 年 9 月 20 日
lsqcurvefit() % optimization toolbox
or
lsqnonlin()

その他の回答 (3 件)

the cyclist
the cyclist 2011 年 9 月 20 日
I don't have either of those toolboxes. I would do this with nlinfit() in the statistics toolbox.

Richard Willey
Richard Willey 2011 年 9 月 22 日
nlinfit uses optimization solvers under the hood, so it's not too surprising that you're getting the same answer.
nlinfit is part of Statistics Toolbox. As such, the function is designed to support typical workflows used by data analysts and provides some additional additional output parameters like R^2. You also have a variety of helper functions that you can use to compute confidence intervals, perform cross validation, and the like.
Optimization Toolbox is a general purpose tool which is both a strength and a weakness. On the plus side, Optimization Toolbox can be used to solve problems that nlinfit can't solve (or can't solve easily). Regression models that involve complex constraints are a classic example. On the down side, if you're trying to do basic data analysis tasks you'll probably need to write a lot more code by hand.

Omar Mian
Omar Mian 2011 年 9 月 22 日
Thanks cyclist & proecsm. I tried both nlinfit and lsqcurvefit and they both do the job. With simulated noisy data, I seem to be getting the same answer from both (to 4 d.p. at least).
What would be the advantage of one over the other? Also, what would be the advantage of lsqnonlin?
  1 件のコメント
John D'Errico
John D'Errico 2011 年 9 月 22 日
The advantage of lsqnonlin is if you do not have the stats toolbox but do have the optimization TB. The advantage of nlinfit is if you DO have the stats TB, and not the optimization TB.

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

カテゴリ

Help Center および File ExchangeLeast Squares についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by