Curve Fitting Using Least Squares Method Bio-Fluids Bien 301 Mootaz Eldib The Problem • Given the value for the density of water over the temperature range of 0-100°C, fit these values to a least squares approximation of the from a bT cT 2 and estimate the accuracy. Calculate the density of water at 45°C and compare it to the actual value of 990.1 Kg/m3. The Problem • Given: (0,1000),(10,1000),(20,998),(30,996),(40,992),(50, 988),(60,983),(70,978),(80,972),(90,965),(100,9 58) Find a bT cT 2 Least Squares Approximation If data given in the form (T1 , 1 ), (T2 , 2 ),....., (Tn , n ) We assume a best fit curve f(t), where the error R for each point is R 1 f (T1 ), R 2 f (T2 ),......., d n n f (Tn ) Square the error and sum over all the points n R 2 d12 d 22 ...... d n2 [ i f (Ti )]2 i Least Squares Approximation • The total error n R 2 d12 d 22 ...... d n2 [ i f (Ti )]2 i is MINIMIZED for least squares method where f (Ti ) a bTi cTi 2 Least Squares Approximation n R 2 2 [ i (a bTi cTi 2 )] 0 a i 1 n R 2 2 [ i (a bTi cTi 2 )] 0 b i 1 n R 2 2 [ i (a bTi cTi 2 )] 0 c i 1 n n n n i 1 i 1 i 1 i 1 2 a 1 b T c T i i i n n n n i 1 i 1 i 1 i 1 2 3 T a T b T c T i i i i i n n n n i 1 i 1 i 1 i 1 2 2 3 4 T a T b T c T i i i i i n n n i 1 Ti i 1 i 1 i 1 n n n 2 T T T i i i i i 1 in1 i n1 n 3 T 2 T 2 T i i i i i 1 i 1 i 1 Ti i 1 n 3 Ti i 1 n 4 T i i 1 n 2 a b c Density Vs Temperature 1005 1000 y = -0.0036t2 - 0.0699t + 1000.6 R2 = 0.9993 995 Density(kg/m^3) 990 985 980 975 970 965 960 955 0 20 40 60 Temp(c) 80 100 120 Solution Density Vs Temperature 1010 1000 y = -0.43t + 1006 R2 = 0.9474 Density(kg/m^3) 990 980 970 960 950 0 20 40 60 80 Temp(c) First order least square approximation Ρ=1006.05 -0.43 t 100 120 Density vs. Temperature 1005 1000 995 3 2 y = 1E-05t - 0.0054t - 0.001t + 1000.2 2 R = 0.9997 Density(kg/m^3) 990 985 980 975 970 965 960 955 0 20 40 60 80 100 Temp(c) Third order approximation. Mathematica equation is 1000.21 0.000971251 t 2 0.00540793 t 3 0.0000120435 t 120 Density vs. Temperature 1005 1000 y = -2E-07t4 + 6E-05t3 - 0.0083t2 + 0.0573t + 1000 R2 = 0.9998 995 Density(kg/m^3) 990 985 980 975 970 965 960 955 0 20 40 60 Temp(c) 80 100 120 Summary • Very powerful method • Widely used • Biomedical engineering application References • http://www.efunda.com/math/leastsquares/ lstsqr2dcurve.cfm • http://mathworld.wolfram.com/LeastSquar esFitting.html • http://math.fullerton.edu/mathews/n2003/L eastSqPolyMod.html Questions?