How to fix one point with no error while curve fitting

조회 수: 5 (최근 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 CenterFile Exchange에서 Get 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