help-octave
[Top][All Lists]
Advanced

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

Re: polyfit -> polyval problem


From: Ben Abbott
Subject: Re: polyfit -> polyval problem
Date: Wed, 22 Jun 2011 10:21:54 -0400

On Jun 22, 2011, at 10:03 AM, Sergei Steshenko wrote:

> --- On Wed, 6/22/11, Ben Abbott <address@hidden> wrote:
> 
>> From: Ben Abbott <address@hidden>
>> Subject: Re: polyfit -> polyval problem
>> To: "Sergei Steshenko" <address@hidden>
>> Cc: address@hidden
>> Date: Wednesday, June 22, 2011, 6:21 AM
>> 
>> On Jun 22, 2011, at 9:16 AM, Sergei Steshenko wrote:
>> 
>>> Hello,
>>> 
>>> I can't figure out what I an doing wrong in the
>> following example:
>>> 
>>> "
>>> octave:42> [p, s, mu] = polyfit ((1:10)(:), 2 *
>> (1:10)(:), 1);
>>> octave:43> p
>>> p =
>>> 
>>>     6.0553   11.0000
>>> 
>>> octave:44> polyval(p, 1:10)
>>> ans =
>>> 
>>>    17.055   23.111   29.166   35.221   41.277   47.332   53.387   59.442   
>>> 65.498   71.553
>>> 
>> 
>> I think the problem is with the syntax you're using for
>> polyval. If "mu" is an output for polyfit(), then it must be
>> used as an input for polval().
>> 
>> octave:3>  [p, s, mu] = polyfit ((1:10)(:), 2 *
>> (1:10)(:), 1);
>> octave:4> polyval(p, 1:10, [], mu)
>> ans =
>> 
>>     2.0000    4.0000   
>> 6.0000   
>> 8.0000   10.0000   12.0000   14.0000   16.0000   18.0000   20.0000
>> 
>> Ben
>> 
>> 
> 
> 
> Thanks.
> 
> Well, this:
> 
> "
> octave:48> p = polyfit ((1:10)(:), 2 * (1:10)(:), 1);
> octave:49> p
> p =
> 
>   2.0000e+00   2.2753e-15
> 
> octave:50> polyval(p, 1:10)
> ans =
> 
>    2.0000    4.0000    6.0000    8.0000   10.0000   12.0000   14.0000   
> 16.0000   18.0000   20.0000
> 
> octave:51>
> "
> 
> also works.
> 
> Now, this is the documentation:
> 
> "
> octave:47> help polyfit
> -- Function File: [P, S, MU] = polyfit (X, Y, N)
>     Return the coefficients of a polynomial P(X) of degree N that
>     minimizes the least-squares-error of the fit.
> 
>     The polynomial coefficients are returned in a row vector.
> 
>     The second output is a structure containing the following fields:
> 
>    `R'
>          Triangular factor R from the QR decomposition.
> 
>    `X'
>          The Vandermonde 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.
> 
>     The second output may be used by `polyval' to calculate the
>     statistical error limits of the predicted values.
> 
>     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.
> 
>     See also: polyval, polyconf, residue.
> 
> /mnt/sdb8/sergei/AFSWD_debug/20110424/octave-3.0.5/share/octave/3.0.5/m/polynomial/polyfit.m
> 
> Additional help for built-in functions and operators is
> available in the on-line version of the manual.  Use the command
> `doc <topic>' to search the manual index.
> 
> Help and information about Octave is also available on the WWW
> at http://www.octave.org and via the address@hidden
> mailing list.
> "
> 
> - could you point exactly which part of the above documentation _clearly_
> explains how to use 'polyval' with 'polyfit' results ?
> 
> I.e., for starters, I do not even see in the documentation that
> 
> p = polyfit(...);
> 
> is a legal form of usage.
> 
> Thanks,
>  Sergei.

Checking the current sources the polyfit() and polyval() docs-trings, it 
appears the lack of clarity has been fixed. The doc-strings are below.

Ben

 -- Function File: P = polyfit (X, Y, N)
 -- Function File: [P, S] = polyfit (X, Y, N)
 -- Function File: [P, S, MU] = polyfit (X, Y, N)
     Return the coefficients of a polynomial P(X) of degree N that
     minimizes the least-squares-error of the fit.

     The polynomial coefficients are returned in a row vector.

     The second output is a structure containing the following fields:

    `R'
          Triangular factor R from the QR decomposition.

    `X'
          The Vandermonde 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.

     The second output may be used by `polyval' to calculate the
     statistical error limits of the predicted values.

     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.

     See also: polyval, residue.


 -- Function File: Y = polyval (P, X)
 -- Function File: Y = polyval (P, X, [], MU)
     Evaluate the polynomial P at the specified values of X.  When MU
     is present evaluate the polynomial for (X-MU(1))/MU(2).  If X is a
     vector or matrix, the polynomial is evaluated for each of the
     elements of X.

 -- Function File: [Y, DY] = polyval (P, X, S)
 -- Function File: [Y, DY] = polyval (P, X, S, MU)
     In addition to evaluating the polynomial, the second output
     represents the prediction interval, Y +/- DY, which contains at
     least 50% of the future predictions.  To calculate the prediction
     interval, the structured variable S, originating form `polyfit',
     must be present.

     See also: polyfit, polyvalm, poly, roots, conv, deconv, residue,
     filter, polyderiv, polyint.






reply via email to

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