Path: news.mathworks.com!not-for-mail
From: "Andrew " <awbsmith@itee.uq.edu.au>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help with orthogonal least squares line fit with slope constraint...
Date: Fri, 14 Dec 2007 03:24:26 +0000 (UTC)
Organization: University of Queensland
Lines: 74
Message-ID: <fjst1a$oc5$1@fred.mathworks.com>
References: <8a0a561b-f3b1-4dcd-8c61-20d0fd4f7cf7@i29g2000prf.googlegroups.com>
Reply-To: "Andrew " <awbsmith@itee.uq.edu.au>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1197602666 24965 172.30.248.35 (14 Dec 2007 03:24:26 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Dec 2007 03:24:26 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1060431
Xref: news.mathworks.com comp.soft-sys.matlab:442421


So after you make your only direction of uncertainty point 
in the y direction what do you want to know about it?

Are you trying to minimise:

sum((X(:,2) - (slope*X(:,1) + b)).^2 where slope is known?

If so, it's b = Xm(2) - slope * Xm(1);

because the least squares solution always passes through 
the mean.

Cheers,
Andrew

P.S

slope = V(2,imx)/V(1,imx);

P.P.S. the regress function is less complicated than your 
eigenvector approach.

Coeffs = regress(X(:,2), [ones(size(X,1),1), X(:,1)]);
b = Coeffs(1); slope = Coeffs(2);





Steve <srjm72499@frontiernet.net> wrote in message 
<8a0a561b-f3b1-4dcd-8c61-
20d0fd4f7cf7@i29g2000prf.googlegroups.com>...
> If I have a group of points, I know I can do a least-
squares line fit
> in the orthogonal sense by doing an eigenvector-type 
approach.  The
> code I've been using for this is:
> 
>     Xm = mean(X);
>     A = cov(X);
>     [V,D] = eig(A);
>     [ignore,imx] = max(diag(D)); % Choose eigenvector 
with max.
> eigenvalue
>     t=4;
>     x = Xm + V(:,imx)'*t;
>     t=-t;
>     x2 = Xm + V(:,imx)'*t;
>     slope=(x2(2)-x(2))/(x2(1)-x(1));
>     b=((x2(2)+x(2))-(slope.*(x(1)+x2(1))))./2;
> 
> Now, I am looking to do a best fit line through the data, 
again in an
> (orthogonal) least-squares sense, but this time where the 
slope of the
> fitting line is a pre-determined (fixed) value.  Is there 
a simple
> solution to this problem?  I am currently getting an 
approximate
> solution by rotating the first line about Xm until it's 
slope is as
> desired, but of course this doesn't always work well.  I 
have
> considered doing a coordinate transform to make the 
predetermined
> slope the x-axis, then doing a standard (non-orthogonal) 
regression
> where the only uncertainty is in the vertical direction, 
but I'm
> guessing there's probably a better way...
> 
> Any thoughts?  Thanks.
> -SL