octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #57964] polyfit() results for polynomial degre


From: José Luis García Pallero
Subject: [Octave-bug-tracker] [bug #57964] polyfit() results for polynomial degree greater or equal than number of data
Date: Fri, 6 Mar 2020 11:49:50 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0

Follow-up Comment #1, bug #57964 (project octave):

Well, I was playing with other values and I noted that in such cases Matlab
does not perform, as I wrote in my firs comment, "the problem is solved using
the correct maximum degree according to the data". But anyway in this cases
the solutions provided by Matlab and Octave are not the same. For example, in
Matlab:

p=polyfit([1 2],[3 4],2)
Warning: Polynomial is not unique; degree >= number of data points. 
> In polyfit (line 70) 

p =

   0.333333333333333                   0   2.666666666666667

and in Octave

p=polyfit([1 2],[3 4],2)
p =

  -0.071429   1.214286   1.857143


If I call the function with a second output argument I can see that the R
matrix of the QR decomposition is the same in both cases, but with different
column ordering (in this case the QR decomposition must be performed with
pivoting). In effect, in Octave we have

>> [p,s]=polyfit([1 2],[3 4],2)
p =

  -0.071429   1.214286   1.857143

s =

  scalar structure containing the fields:

    yf =

       3.0000   4.0000

    X =

       1   1   1
       4   2   1

    R =

      -4.12311  -1.21268  -2.18282
       0.00000  -0.72761  -0.48507

    C =

       NaN   NaN   NaN
       NaN   NaN   NaN
       NaN   NaN   NaN

    df = -1
    normr =    1.2561e-15

so the QR decomposition was performed with pivoting as

>> [q,r,p]=qr(s.X)
q =

  -0.24254  -0.97014
  -0.97014   0.24254

r =

  -4.12311  -1.21268  -2.18282
   0.00000  -0.72761  -0.48507

p =

Permutation Matrix

   1   0   0
   0   0   1
   0   1   0


Apparently Matlab does not use pivoting in the QR, but I can't check it as the
polyfit() output struct in Matlab does not store the Vandermonde matrix of the
problem, but if I use the Octave's one I obtain

>> [q,r]=qr(s.X)
q =

  -0.24254  -0.97014
  -0.97014   0.24254

r =

  -4.12311  -2.18282  -1.21268
   0.00000  -0.48507  -0.72761

which is the Matlab's result.

So my original submission must not be considered a bug nor incorrect result,
but an incompatibility with Matlab.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57964>

_______________________________________________
  Mensaje enviado vía Savannah
  https://savannah.gnu.org/




reply via email to

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