y=a+bx Linear Regression: Method of Least Squares slope y intercept 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 (xn; yn) are observed. The form of the fitted curve is Sum of squares of errors slope y=a+bx y intercept
Example 1: Find a 1st order polynomial y=a+bx for the values given in the table. -5 -2 2 4 7 3.5 a=1.188 b=0.484 y=1.188+0.484x With Matlab: 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,'ro',x1,yx,'b') xlabel('x value') ylabel ('y value') Data point Fitted curve
Example 2: x y 200 3 230 5 240 8 270 10 290 y=a+bx y=200.13 + 8.82x 200 3 230 5 240 8 270 10 290 y=a+bx y=200.13 + 8.82x 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,'ro',x1,yx,'b') xlabel('x value') ylabel ('y value') Data point Fitted curve
Example 3: Intercept Slope 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
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,F); plot(x,y,'ro‘,F,a,'b') xlabel('x value') ylabel ('y value')
Example 4: 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=c1t+c2. Determine the coefficients c1 and c2. T (°C) t (min.) 0 5 10 15 175 204 200 212 Slope Intercept
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,t); plot(x,y,'ro',t,T,'b') xlabel('x value') ylabel ('y value‘) with Matlab: