Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!nrc-news.nrc.ca!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Determine if points are in a straight line?
Date: Fri, 10 Sep 2010 14:28:15 -0500
Organization: Canada Eat The Cookie Foundation
Lines: 33
Message-ID: <i6e0vv$mgn$1@canopus.cc.umanitoba.ca>
References: <i6dvfn$qg3$1@fred.mathworks.com>
NNTP-Posting-Host: ibd-nat.ibd.nrc.ca
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: canopus.cc.umanitoba.ca 1284147007 23063 132.246.133.10 (10 Sep 2010 19:30:07 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Fri, 10 Sep 2010 19:30:07 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.12) Gecko/20100826 Thunderbird/3.0.7
In-Reply-To: <i6dvfn$qg3$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:669193

On 10-09-10 02:04 PM, J D wrote:
> Is there a quick way to check if a set of points are in a straight line?
>
> Ex/
> data = [8.6401 4.2324
> 8.6465 4.2592
> 8.6453 4.2542]
>
> islinear(data(:,1),data(:,2)) = 1

 >> Q = polyfit(data(:,1),data(:,2),1);
Q =
           4.18894009216628         -31.9604585253489
 >> Q(1) * data(:,1) + Q(2) - data(:,2)
ans =
       2.76497695672617e-06
       1.19815668178092e-05
      -1.47465437754235e-05

As these values are not 0 to within a small multiple of eps(data(:,1)), it 
follows that the points are NOT in a straight line.

 >> Q = polyfit(data(:,1),data(:,2),2)
Q =
          -4.00641025800001          73.4447115659304         -331.253406088208
 >> Q(1) * data(:,1).^2 + Q(2) * data(:,1) + Q(3) - data(:,2)
ans =
       4.08562073062058e-14
       -9.2370555648813e-14
      -8.79296635503124e-14

Thus with a quadratic, the fit is good and by examining the coefficients the 
points are clearly non-linear.