[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Curve Fitting "splattered" data

From: Rafael Laboissiere
Subject: Re: Curve Fitting "splattered" data
Date: Mon, 18 Oct 2004 04:07:02 -0500
User-agent: Mutt/1.5.6+20040722i

* Robert A. Macy <address@hidden> [2004-10-17 23:36]:

> Trying to fit a curve to data with poor results.
> Data is a set of 37 complex data points that roughly lie
> along a straight line in the complex plane.  Sequence of
> data has no significance, only their location on the plane.
> Don't care about intercept point, only the slope.  Ran
> polyfit.m using  real(datapoints) and imag(datapoints)  
> thinking that would yield slope of trend, for example,
> p=polyfit(real(datapoints),imag(datapoints),1)
> calculates a slope, but when I reverse the order
> p=polyfit(imag(datapoints),real(datapoints),1)
> I don't get a reciprocal slope?!  
> one way I get 15.093, the other way I get 0.0228387
> Why aren't they reciprocal? 

Because in the first case you minimize the sum of squared errors in
imag(datapoints) and in the second case in real(datapoints).  This is the
expected behavior of polyfit (see "help polyfit").

> Is there a better program for finding the straight line?

You might do a PCA (principal component analysis) on your data, which boils
down to using either eig or svd.  Try this:

    d = [real(datapoints), imag(datapoints)];
    [u,v,w] = svd (cov (d));
    m = mean (d);
    r = min (d (:, 1));
    s = max (d (:, 1));
    hold off    
    plot (d (:, 1), d (:, 2), '*')    
    hold on 
    plot ([r, s], m (2) + [(r-m(1)),(s-m(1))] * u(2) / u(1));

The slope of the curve plotted is close to -0.022861.


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]