least squares linear fit to be forced to pass through a specified point

Answers (1)

Do you have the Statistics Toolbox? If so, you could use the nlinfit() function to do this. Here is a simple example that you might be able to tailor to your needs:
% Data
x = 1:8;
y = 3*x + 0.4*rand(1,8);
% Example of linear model through a fixed point
f = @(p,x) p(1)*x - 0.2;
% Fit
beta0 = [1];
[beta,r,j,covb,mse] = nlinfit(x,y,f,beta0)

Asked:

on 7 Aug 2011

Community Treasure Hunt

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

Start Hunting!