Polyfit with scaling

Ben Abbott bpabbott at mac.com
Mon Feb 4 19:01:08 CST 2008


On Feb 4, 2008, at 7:44 PM, Dmitri A. Sergatskov wrote:

> On Feb 4, 2008 6:16 PM, Ben Abbott <bpabbott at mac.com> wrote:
>>
>> On Feb 4, 2008, at 4:21 PM, Dmitri A. Sergatskov wrote:
>>
>>> -- if std(x) == 0 then it means that all x are the same number (I
>>> would also argue that one
>>>   may want to compare to eps rather than 0). In that case we cannot
>>> do any fits,
>>>   so probably should just exit with an error.
>>
>> Moving the bar to something greater than zero will be a problem if  
>> the
>> x values are small to begin with. Instead, I think we should make a
>> comparison relative to the mean.
>>
>> How about "if std(x) < mean(x)*eps" ?
>>
>
> No, the constant should be O(1). It is not unreasonable to expect
> for x to be > 1/eps that is only 4.3e15 on my computer.
> In fact, now I think that we do not need this check at all.
> With the current wpolyfit I get:
> octave:28> x=ones(1e3,1); y=2*x;
> octave:29> [p, s, mu]=wpolyfit (x,y, 1)
> warning: division by zero
> p =
>
>   NaN   NaN
>
> s =
> {
>  R =
>
>     NaN   NaN
>       0   NaN
>
>  df =  998
>  normr = NaN
> }
>
> mu =
>
>   1   0
>
> Which looks to me as a reasonable way to handle the situation.

Ok, I agree.

My concern was with regards to zeroth order polynomials. However,  
after checking ... there isn't a problem.

octave:190> [p, s, mu] = polyfit ([1 1], [2 2], 0)
warning: division by zero
p =  2.0000
s =
{
   yf =

      2.0000   2.0000

   R = -1.4142
   X =

      1
      1

   df =  1
   normr =  9.4206e-16
}

mu =

    1   0

I'm now confused as to your position. Do you wish to do any check on  
mu(2) or just leave it as it is?

Ben






More information about the Octave-maintainers mailing list