How to fix one point with no error while curve fitting

11 ビュー (過去 30 日間)
aneps
aneps 2014 年 6 月 9 日
コメント済み: curoi 2015 年 1 月 14 日
I have a data to fit linear plot. But I want to fit the first point with no error. I mean, the fitted curve should fix on the first point and then fit to the rest of the point in 'least square fit' method. How can I do that?

採用された回答

Shashank Prasanna
Shashank Prasanna 2014 年 6 月 9 日
編集済み: Shashank Prasanna 2014 年 6 月 10 日
[Edited] removed least squares comment
You could give more importance to the first observation using weights, I do this using the fitlm function in the statistics toolbox:
x = 1:10; y = randn(10,1);
lm1 = fitlm(x,y);
lm2 = fitlm(x,y,'weights',[100, ones(1,length(y)-1)]);
scatter(x,y), hold on
plot(x, lm1.Fitted,'r')
plot(x, lm2.Fitted,'b')
  9 件のコメント
John D'Errico
John D'Errico 2015 年 1 月 14 日
If there are intrinsically nonlinear parameters to estimate, then no, lsqlin will not suffice. It solves only problems that are linear in the parameters. However, you CAN construct a model which will pass through a point exactly for a sinusoidal model, or have a variety of fixed properties. I assume your question relates to the one you posed recently on answers. I'm sorry, but that was a confusing question that I chose not to answer, partly because it was not at all clear what form your data was in, what form the model took on, etc. It looked like you had only a blurry image, and needed to extract a model of some form from that.
curoi
curoi 2015 年 1 月 14 日
Yeah, sorry about that. It does have to do with the question asked but I didn't realize the images were so blurry. I do just want to 'construct a model which will pass through a point exactly for a sinusoidal model' although it may be several points and multiple sine terms if that's possible.
The data is just in a form according to the indices of the image.

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

その他の回答 (1 件)

Matt J
Matt J 2014 年 6 月 9 日
It depends on the model function for your curve. Ideally, you would choose the formula for the curve to be such that it passes through the desired point. For example, the following linear curve function has unknown slope parameter m, but is written so that it always passes through the known point (x0,y0)
y=m*(x-x0)+y0
If the formula for your model is not tractable enough for this, you may need to use fmincon to do the curve-fitting and specify your constraint using the nonlcon argument.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by