Lecture10b

Lecture10b - 0306-381 Applied Programming üNumerical...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-381 Applied Programming üNumerical Integration FLeast Squares Curve Fitting Curve Fitting Process of analyzing data in an attempt to find a formulaic expression for the output as a function of input • Function f (x) to approximate value of y for a given value of x • (x, f (x)) for input/output relationship: (x, y) • Typically off-line process 16 Curve Fitting Example Design of digital display for relative humidity • Display: percentage scale from 0% to 100% • Sensor: outputs voltage, which is proportional to ambient humidity • Problem: sensor is nonlinear 17 Curve Fitting Goal What is goal for function to approximate data? • Accuracy • Produce minimum error 18 Linear Approximation Find a straight line that passes through a set of data points Data Points (Y vs. X) y = x - 6.3333 25 20 15 Y Y 10 5 0 10 15 20 X 25 30 19 Linear Least-Squares Approximation Minimize error using least squares method: y » f (x) • f (x) = ax + b • f (x) minimizes total squared error Error = å ( f ( xi ) - yi ) i 2 20 Linear Approximation: Total Squared Error Minimization For f (x) = ax + b, total squared error can be expressed as a function of a and b. Error = å ((axi + b) - yi ) i 2 • To minimize error in, find a and b values to give zero from partial derivatives of Error with respect to a and with respect to b ¶Error ¶Error = 0; =0 ¶a ¶b 21 Linear Approximation: Minimum Total Squared Error Solution of partial differential equations a= N ´ S xy - S x ´ S y N ´ S xx - S x ´ S x b= S xx ´ S y - S xy ´ S x N ´ S xx - S x ´ S x where S xx = å xi i =1 N N 2 S x = å xi i =1 N N S xy = å xi ´ yi i =1 S y = å yi i =1 22 Linear Least-Squares Approximation Example Three data points (N = 3) • (x1, y1) = (15, 10) • (x2, y2) = (20, 11) • (x3, y3) = (25, 20) • Sxx = 152 + 202 + 252 = 1250 • Sxy = 15 ´ 10 + 20 ´ 11 + 25 ´ 20 = 870 • Sx = 15 + 20 + 25 = 60 • Sy = 10 + 11 + 20 = 41 23 Linear Least-Squares Approximation Example Solution y » f (x) = ax + b N ´ S xy - S x ´ S y 3 ´ 870 - 60 ´ 41 = a= N ´ S xx - S x ´ S x 3 ´1250 - 60 ´ 60 150 = 150 = 1.00 1250 ´ 41 - 870 ´ 60 b= = N ´ S xx - S x ´ S x 3 ´ 1250 - 60 ´ 60 - 950 = 150 = -6.33 S xx ´ S y - S xy ´ S x 24 Linear Least-Squares Approximation Example Result Data and Linear Least-Squares Approximation 21 19 17 15 13 11 9 7 5 10 15 20 18.66666667 Y f(x) Y 13.66666667 10 8.666666667 11 20 X 25 30 25 Quadratic Least-Squares Approximation Minimize error using least squares method: y » f (x) • f (x) = ax2 + bx + c • f (x) minimizes total squared error Error = å ( f ( xi ) - yi ) i 2 = å (ax + bx + c) - yi 2 i ( ) 2 • Find variables a, b, and c to minimize partial derivatives of Error with respect to each variable 26 Quadratic Approximation: Minimum Total Squared Error y » f (x) = ax2 + bx + c a × å xi4 + b × å xi3 + c × å xi2 = å xi2 × yi i =1 n i =1 n i =1 n i =1 n n n n n a × å x + b × å x + c × å x i = å xi × y i 3 i 2 i i =1 n i =1 n i =1 i =1 a × å xi2 + b × å xi + c × n = å yi i =1 i =1 i =1 n Solution of set of 3 simultaneous equations of 3 variables 27 Least-Squares Approximation with Function of Order n Minimize error using least squares method y » f ( x ) = å ak x k k =0 n Error = å ( f ( xi ) - yi ) i n 2 éæ ù kö = å êç å ak x ÷ - yi ú i ëè k = 0 ø û ì ¶Error ü = 0ý"k Î [0, n] í î ¶ak þ 2 28 ...
View Full Document

This note was uploaded on 04/27/2010 for the course EECC 0306-381 taught by Professor Roymelton during the Spring '10 term at RIT.

Ask a homework question - tutors are online