How to fix one point with no error while curve fitting

2 views (last 30 days)
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?

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 9 Jun 2014
Edited: Shashank Prasanna on 10 Jun 2014
[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 Comments
John D'Errico
John D'Errico on 14 Jan 2015
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 on 14 Jan 2015
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.

Sign in to comment.

More Answers (1)

Matt J
Matt J on 9 Jun 2014
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.

Community Treasure Hunt

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

Start Hunting!