bugGNU Octave - Bugs: bug #46126, Polyfit bug: Different polynomial...

 
 

bug #46126: Polyfit bug: Different polynomial coefficients when using optional output

Submitter:  None
Submitted:  Mon 05 Oct 2015 07:49:56 AM UTC
   
 
Category:  Documentation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Nicole Dröge Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.0.0
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 05 Oct 2015 11:46:53 AM UTC, comment #4: 

Then leave it as it is.
Thank you!

Nicole Dröge <droegen>
Mon 05 Oct 2015 11:43:02 AM UTC, comment #3: 

Indeed sometimes separating the various calling forms of a function seams to lead to clearer doc. On the other hand, you have to walk through the whole doc to discover all the calling forms; hence the choice, for the whole Octave functions docs, to group all calling forms at the beginning of the doc.

If you can think of a clear improvement of the doc that preserves the list of interfaces at the beginning I may integrate it but not otherwise.

Pantxo Diribarne <pantxo>
Group Member
Mon 05 Oct 2015 11:07:38 AM UTC, comment #2: 

Hi,

ok. I think the doc is really a little bit irritating.
Maybe you change the order of explanations, something like this:

p = polyfit (x, y, n ) [Function File]
[p, s ] = polyfit (x, y, n ) [Function File]
Return the coeffients of a polynomial p(x) of degree n that minimizes the leastsquares-error of the fit to the points [x, y].
The p olynomial co effients are returned in a row vector.
The optional output s is a structure containing the following filds:
‘R’ Triangular factor R from the QR decomposition.
‘X’ The Vandermonde matrix used to compute the polynomial coeffients.
‘df’ The degrees of freedom.
‘normr’ The norm of the residuals.
‘yf’ The values of the polynomial for each value of x.
The second output may be used by polyval to calculate the statistical error limits
of the predicted values.

[p, s, mu] = polyfit (x, y, n ) [Function File]
When the third output, mu, is present the coeffients, p, are 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.


But I don't know if it fits to the guidelines for writing a doc.

Nicole Dröge <droegen>
Mon 05 Oct 2015 10:02:41 AM UTC, comment #1: 

Hi,

Looks like requesting the third coefficient changes the signification of the P output, as written in the doc:


When the third output, MU, is present the coefficients, P, are
     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.


So it must be used as following:


x = 1:100;
y = sin (2*pi*x/100) + 0.3*rand(1,100);
plot (x, y)
hold on
p = polyfit (x, y, 3); % normal polynomial coeffs.
plot (x, polyval (p, x), "-k")
[p, s, mu]  = polyfit (x, y, 3); % modified polynomial coeffs.
xx = (x-mu(1))/mu(2);
plot (x, polyval (p, xx), "-m")


Can I close this report or do you think the documentation should be modified. It was quite clear to me how to use modified polynomial coeffs though.

Pantxo Diribarne <pantxo>
Group Member
Mon 05 Oct 2015 07:49:56 AM UTC, original submission:  

Using the polyfit function without the optional arguments

p1 = polyfit(x,y,N)

gives different polynomial coefficients p than using polyfit with the optional arguments

[p2,s,mu] = polyfit(x,y,N)

My expectation and understanding of the polyfit doc is that p1=p2, but it is p1!=p2.
I am using an Win 7, 64 bit system with MinGW-32bit.

Attached I send an input file, which produces the error, and also log files of Octave 4.0.0 and 3.6.4 of the console output where the results can be reviewed.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #35066:  Bug_polyfit.m added by None (1KiB - application/octet-stream - Input file, which produces the bug, and output files with calculation results)
file #35067:  Bug_polyfit_Octave3.6.4.out added by None (1KiB - application/octet-stream - Input file, which produces the bug, and output files with calculation results)
file #35068:  Bug_polyfit_Octave4.0.0.out added by None (1KiB - application/octet-stream - Input file, which produces the bug, and output files with calculation results)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by droegen (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-10-05 pantxo StatusWorks For Me Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2015-10-05 pantxo CategoryOctave Function Documentation
    2015-10-05 pantxo StatusNone Works For Me
    2015-10-05 None Attached File- Added Bug_polyfit.m, #35066
        Attached File- Added Bug_polyfit_Octave3.6.4.out, #35067
        Attached File- Added Bug_polyfit_Octave4.0.0.out, #35068

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code