Fitting a polynomial model to the data

73 Views Asked by At

I want to fit a line to the following data. But the line I have obtained is far from the data. What is wrong in the following least square problem?

>> data =
         0    2.4500
   20.0000   18.6200
   40.0000   16.3700
   60.0000   19.4000
   80.0000   24.5000
  100.0000   24.0100
  120.0000    8.7200
  140.0000    9.7000
  160.0000   10.1900
  180.0000   10.6800
  200.0000   11.1700
  220.0000   11.8600
  240.0000   12.4500
  260.0000   13.2300
  280.0000   13.9200
  300.0000   14.9000
  320.0000   15.9700
  340.0000   17.1500
  360.0000   18.6200
  380.0000   20.2900
  400.0000   22.3400
  420.0000   24.8900
  440.0000   28.0300
  460.0000   29.0100
  480.0000   29.3000
  500.0000   29.0100
  520.0000    0.1000

>> A = ones(27,1); A = [A data(:,1)];
>> ls = A\data(:,2)
ls =
   11.9998
    0.0189

>> plot(data(:,1), data(:,2), 'o')
>> hold all; plot(data(:,1), polyval(ls, data(:,1)))

enter image description here

>> plot(data(:,1), data(:,2), 'o')

enter image description here

1

There are 1 best solutions below

2
On BEST ANSWER
  1. The first six values and the last do not seem to be part of the same trend as the other points

  2. The other points do not seem to follow a linear trend

  3. The fitted line you have drawn seems to have swapped the intercept and gradient

Here is what your data looks like in Excel

enter image description here