y=a+bx Sum of squares of errors Linear Regression: Method of Least Squares The Method of Least Squares is a procedure to determine the best fit line to data; the proof uses simple calculus and linear algebra. The basic problem is to find the best fit straight line y = a + bx given that, for n {1,…,N}, the pairs (x n ; y n ) are observed. The form of the fitted curve is y intercept slope
xy a=1.188 b=0.484 y= x Example 1: Find a 1 st order polynomial y=a+bx for the values given in the Table. Data point Fitted curve clc;clear x=[-5,2,4]; y=[-2,4,3.5]; p=polyfit(x,y,1) x1=-5:0.01:7; yx=polyval(p,x1); plot(x,y,'or',x1,yx,'b') xlabel('x value') ylabel ('y value')
xy y=a+bx y= x Example 2: clc;clear x=[0,3,5,8,10]; y=[200,230,240,270,290]; p=polyfit(x,y,1) x1=-1:0.01:12; yx=polyval(p,x1); plot(x,y,'or',x1,yx,'b') xlabel('x value') ylabel ('y value') Data point Fitted curve
Method of Least Squares: Tensile tests were performed for a composite material having a crack in order to calculate the fracture toughness. Obtain a linear relationship between the breaking load F and crack length a. Method of Least Squares Slope Intercept Slope Intercept
Method of Least Squares: with Visual Basic: mls.txt 5 10, , , , ,0.28 with Matlab: clc;clear x=[10,9.25,9.1,9.4,8.5]; y=[0.5,0.4,0.35,0.45,0.28]; p=polyfit(x,y,1) F=8:0.01:12; a=polyval(p,x1); plot(x,y,'or‘,F,a,'b') xlabel('x value') ylabel ('y value')
Method of Least Squares: The change in the interior temperature of an oven with respet to time is given in the Figure. It is desired to model the relationship between the temperature (T) and time (t) by a first order polynomial as T=c 1 t+c 2. Determine the coefficients c 1 and c 2. T (°C) t (min.) Slope Intercept Slope Intercept
Method of Least Squares: With Visual Basic: mls.txt 4 0,175 5,204 10,200 15,212 with Matlab: clc;clear x=[0,5,10,15]; y=[175,204,200,212]; p=polyfit(x,y,1) t=0:0.01:15; T=polyval(p,x1); plot(x,y,'or',t,T,'b') xlabel('x value') ylabel ('y value')