[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: need help with polyfit and polyval
From: |
Dmitri A. Sergatskov |
Subject: |
Re: need help with polyfit and polyval |
Date: |
Mon, 6 May 2019 09:54:11 -0500 |
On Mon, May 6, 2019 at 9:50 AM Dmitri A. Sergatskov
<address@hidden> wrote:
>
>
>
> On Mon, May 6, 2019 at 9:31 AM Doug Stewart <address@hidden> wrote:
>>
>> I am trying to convert some data from wikipedia to octave and I ran into
>> this problem.
>>
>> here is the code
>> **********************************************
>> data = [ 4.0000 3.1000
>> 5.0000 4.7400
>> 6.0000 6.1300
>> 7.0000 7.2600
>> 8.0000 8.1000
>> 9.0000 8.1400
>> 10.0000 8.7400
>> 11.0000 8.7700
>> 12.0000 9.1300
>> 13.0000 9.1400
>> 14.0000 9.2600 ];
>> x = data(:,1);
>> y = data(:,2);
>> [P, S, MU] = polyfit (x, y, 1)
>> y3=S.yf
>> y2=polyval(P,x)
>>
>> plot(x,y,'x',x,y,x,y2,x,y3)
>>
>> **********************************************
>>
>>
>> poly fit should return the polynomial in P
>> But when i use it in polyval it is obviously wrong.
>> but polyfit also returns the new calculated y values in S.yf.
>> S.yf look correct ut P seems to be wrong.
>> I get
>> P = 1.8410 7.5009
>> which is y=x*1.841 + 7.5009
>> and this is obviously wrong.
>
>
> Yes. It looks like
> [P, S, MU] = polyfit (x, y, 1) form has a problem.
> if you just do p = polyfit (x, y, 1)
> you get a correct p:
> P=polyfit (x,y,1)
> P =
>
> 0.55509 2.50509
>
> octave:12> y2=polyval(P,x)
> y2 =
>
> 4.7255
> 5.2805
> 5.8356
> 6.3907
> 6.9458
> 7.5009
> 8.0560
> 8.6111
> 9.1662
> 9.7213
> 10.2764
>
In fact it looks like a feature, from the help:
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).
I think text in help can be improved
>
>
> Dmitri.
> --
>
Dmitri.