How to fix one point with no error while curve fitting

5 次查看(过去 30 天)
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-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