help-octave
[Top][All Lists]
Advanced

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

need help with polyfit and polyval


From: Doug Stewart
Subject: need help with polyfit and polyval
Date: Mon, 6 May 2019 10:28:19 -0400

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.

Can someone run this and see if you get what I get?
And why is polyfit giving back a wrong P for this data set?







--
DASCertificate for 206392


reply via email to

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