Polyfit with scaling

Ben Abbott bpabbott at mac.com
Mon Feb 4 14:32:16 CST 2008


I've modified polyfit.m to be consistent with the Matlab's version.

In short, "help polyfit" replies

octave:168> help polyfit
 -- Function File: [P, S, MU] = polyfit (X, Y, N)
     Return the coefficients of a polynomial P(X) of degree N that
     minimizes `sumsq (p(x(i)) - y(i))',  to best fit the data in the
     least squares sense.

     The polynomial coefficients are returned in a row vector.

     If a second output argument is requested a structured variable, S,
     containing the following fields will be returned:

    `R'
          Triangular factor R from the QR decomposition.

    `X'
          The Vandermonde matrix matrix used to compute the polynomial
          coefficients.

    `df'
          The degrees of freedom.

    `normr'
          The norm of the residuals.

    `yf'
          The values of the polynomial for each value of X.

     When the third output, MU, is requested, POLYFIT will return the
     coefficients associated with a polynomial in XHAT =
     (X-MU(1))/MU(2).  Where MU(1) = mean (X), and MU(2) = std (X).
     This linear transformation of X improves the numerical stability
     of the fit.

I've attached the modified script. I'd appreciate anyone's effort in testing it functionality, comparing to Matlab, and/or improving the help documentation.

In the meantime, I'll be looking at polyval. It also needs to be modified to take mirror these changes. Specifically, polyval needs to accept additional inputs if it is to be compatible/consistent with Matlab's version. There are four possible ways polyval may be called;

y = polyval (p, x);
[y, delta] = polyval (p, x, s);
y = polyval (p, x, [], mu);
[y, delta] = polyval (p, x, s, mu);

Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: polyfit.m
Type: application/octet-stream
Size: 4807 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080204/21dde915/attachment-0001.obj 


More information about the Octave-maintainers mailing list