Tuesday, September 13, 2005

fit curve, fit line

In matlab, fitline fit-line


[coolcode "linenum="off"]

x = 0:5;

y = [0 20 60 68 77 110];

a = polyfit(x,y,1)

yhat = polyval(a,x);

err = yhat - y

MSE = mean(err.^2)

RMSE = sqrt(MSE)

plot(x,y,'o',x,yhat),title('Linear Regression'),...

xlabel('time, s'),ylabel('Temperature, degrees F'),...

grid,axis([-1,6,-2,120]),legend('measured','estimated',4)[/coolcode]


Running this script:

a =

20.8286 3.7619

err =

3.7619 4.5905 -14.5810 -1.7524 10.0762 -2.0952

MSE =

59.4698

RMSE =

7.7117

Thus, the best linear fit is

ˆy = 20.8286x + 3.7619

and the root mean squared error is 7.71,

No comments:

Post a Comment