help-octave
[Top][All Lists]

## polyfit -> polyval problem

 From: Sergei Steshenko Subject: polyfit -> polyval problem Date: Wed, 22 Jun 2011 06:16:31 -0700 (PDT)

```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

octave:45> s.yf
ans =

2.0000
4.0000
6.0000
8.0000
10.0000
12.0000
14.0000
16.0000
18.0000
20.0000

octave:46>
".

First of all, contents of 'p':

"
p =

6.0553   11.0000
"

do not make sense to. Because of the contents the result of reconstitution:

"
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
".

doesn't make sense either.

But the 'yf' values are OK:
"
octave:45> s.yf
ans =

2.0000
4.0000
6.0000
8.0000
10.0000
12.0000
14.0000
16.0000
18.0000
20.0000
".

What am I missing here ?

It look like I can still use 'polyfit' (I need to fit a straight line) by
simply using the first and the last value of 'yf' to calculate 'k' and 'b'
for y = k * x + b .

Thanks,
Sergei.

```