35p. Curvefitting _printable_

35p. Curvefitting _printable_ - Guessing the Fitted Line...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 ©2009 by L. Lagerstrom Curvefitting • For an introduction to the basic concepts, see the associated video clip • Guessing the fitted line • Checking the fit: the MSE and RMSE • Finding the best fit line using polyfit • Fitting higher order polynomials Matlab code Figure window display ©2009 by L. Lagerstrom Guessing the Fitted Line %Consider some (x,y) values repre- %senting temperature vs. time %measurements. x = 0:5 y = [0 20 60 68 77 110] %Make an educated guess that the %line y_hat = 20*x will fit the %data well (i.e., slope of 20 and %y-intercept = 0). So plot the %(x,y) data and the y-hat line %on the same plot to check the fit. %We will plot the data points as %blue squares and the y_hat %estimate line in red. y_hat = 20*x; figure(1), clf plot(x,y,'s',x,y_hat,'r') title('Linear Estimate') xlabel('Time (s)') ylabel('Temp (deg F)') grid, axis([-1, 6, -2, 120]) legend('measured','estimated',4) 0 2 4 6 0 20 40 60 80 100 120 Linear Estimate Time (s) Temp (deg F) measured estimated Matlab code Command window display ©2009 by L. Lagerstrom Checking the Fit: the MSE %To see how well the y_hat line fits %the data, calculate the mean %squared error by: %1. Calculating the vertical %distance from each data point to %the line (this is the "error"). %2. Squaring each vertical distance %(this is the "squared error"). %3. Summing the squared-error values %and calculating the mean (this is %the "mean squared error," or MSE). %Redisplay (x,y) data and y_hat line %values for reference x = 0:5, y = [0 20 60 68 77 110] y_hat = 20*x %Calculate the errors and MSE err = y_hat - y MSE = mean(err.^2) x = 0 1 2 3 4 5 y = 0
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2010 for the course ENG 42325 taught by Professor Lagerstrom during the Spring '10 term at UC Davis.

Page1 / 3

35p. Curvefitting _printable_ - Guessing the Fitted Line...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online