
Interpolation and Curve fitting Spring 2019 Interpolation and Curve fitting Spring 2019 1 / 19 Curve fitting Find a function that is a good fit to the original data points The function does not have to pass through the original data points. Interpolation vs Curve fitting n Given some data points fxi ; yi gi=1 and assuming there is some function f (x) describes the quantity of interest at all points. Interpolation Find a function satisfying P(xi ) = f (xi ); i = 1;:::; n that allows us to approximate f (x) such that the function values between the data sets may be estimated. Interpolation and Curve fitting Spring 2019 2 / 19 Interpolation vs Curve fitting n Given some data points fxi ; yi gi=1 and assuming there is some function f (x) describes the quantity of interest at all points. Interpolation Find a function satisfying P(xi ) = f (xi ); i = 1;:::; n that allows us to approximate f (x) such that the function values between the data sets may be estimated. Curve fitting Find a function that is a good fit to the original data points The function does not have to pass through the original data points. Interpolation and Curve fitting Spring 2019 2 / 19 Piecewise Linear Interpolation Simplest case: 2 points Basic algebra problem Given two points (x1; f (x1)) and (x2; f (x2)), find P1(x) such that P1(x1) = f (x1) P2(x2) = f (x2) P1 can be written in the form x − x2 x − x1 P1(x) = f (x1) + f (x2) x1 − x2 x2 − x1 Interpolation and Curve fitting Spring 2019 3 / 19 Exercise: Interpolate 10 random data points with values on [0; 10] and evaluate the polynomial on 1:0.1:10 and plot. Linear Interpolation 9 8 7 6 y 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 x Interpolation in MATLAB interp1 vq = interp1(x,v,xq,method) x { sample points v { values f (x) xq { query points on which the polynomial will be evaluated method { method of interpolation (e.g. linear, cubic, e.t.c) Interpolation and Curve fitting Spring 2019 4 / 19 Linear Interpolation 9 8 7 6 y 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 x Interpolation in MATLAB interp1 vq = interp1(x,v,xq,method) x { sample points v { values f (x) xq { query points on which the polynomial will be evaluated method { method of interpolation (e.g. linear, cubic, e.t.c) Exercise: Interpolate 10 random data points with values on [0; 10] and evaluate the polynomial on 1:0.1:10 and plot. Interpolation and Curve fitting Spring 2019 4 / 19 Higher order interpolation : Lagrange interpolant Idea: Lagrange (1736 - 1813) Given n + 1 data points (x1; f (x1)); (x2; f (x2));:::; (xn; f (xn)); (xn+1; f (xn+1)) , define a polynomial n+1 X P(x) = f (xj )'j (x) i=1 where ( 0 if j = i 'j (xi ) = δij = 1 if j 6= i Interpolation and Curve fitting Spring 2019 5 / 19 Notice that: 1 0 x − x ¨¨* x − x ¨¨* P (x ) = 1 ¨2 f (x ) + 1 ¨1 f (x ) = f (x ) 1 1 ¨¨ 1 ¨¨ 2 1 ¨x1 − x2 ¨x2 − x1 ¨* 0 ¨* 1 x2 − x2¨ x2 − x1¨ P (x ) = ¨¨ f (x ) + ¨¨ f (x ) = f (x ) 1 2 ¨ 1 ¨ 2 2 ¨x1 − x2 ¨x2 − x1 What does '(x) look like? In the linear case: x − x2 x − x1 P1(x) = f (x1) + f (x2) x1 − x2 x2 − x1 Interpolation and Curve fitting Spring 2019 6 / 19 ¨* 0 ¨* 1 x2 − x2¨ x2 − x1¨ P (x ) = ¨¨ f (x ) + ¨¨ f (x ) = f (x ) 1 2 ¨ 1 ¨ 2 2 ¨x1 − x2 ¨x2 − x1 What does '(x) look like? In the linear case: x − x2 x − x1 P1(x) = f (x1) + f (x2) x1 − x2 x2 − x1 Notice that: 1 0 x − x ¨¨* x − x ¨¨* P (x ) = 1 ¨2 f (x ) + 1 ¨1 f (x ) = f (x ) 1 1 ¨¨ 1 ¨¨ 2 1 ¨x1 − x2 ¨x2 − x1 Interpolation and Curve fitting Spring 2019 6 / 19 What does '(x) look like? In the linear case: x − x2 x − x1 P1(x) = f (x1) + f (x2) x1 − x2 x2 − x1 Notice that: 1 0 x − x ¨¨* x − x ¨¨* P (x ) = 1 ¨2 f (x ) + 1 ¨1 f (x ) = f (x ) 1 1 ¨¨ 1 ¨¨ 2 1 ¨x1 − x2 ¨x2 − x1 ¨* 0 ¨* 1 x2 − x2¨ x2 − x1¨ P (x ) = ¨¨ f (x ) + ¨¨ f (x ) = f (x ) 1 2 ¨ 1 ¨ 2 2 ¨x1 − x2 ¨x2 − x1 Interpolation and Curve fitting Spring 2019 6 / 19 where: (x − x2)(x − x3) (x − x1)(x − x3) (x − x1)(x − x2) '1(x) = ;'2(x) = ;'3(x) = (x1 − x2)(x1 − x3) (x2 − x1)(x2 − x3) (x3 − x1)(x3 − x2) In the general case, given n + 1 data points we can write down the Lagrange interpolating polynomial of degree n of this form What does '(x) look like? Therefore: P1(x) = '1(x)f (x1) + '2(x)f (x2) where x − x2 x − x1 '1(x) = ;'2(x) = x1 − x2 x2 − x1 In the case of 3 data points (x1; f (x1)); (x2; f (x2)); (x3; f (x3)) P2(x) = '1(x)f (x1) + '2(x)f (x2) + '3(x)f (x3) Interpolation and Curve fitting Spring 2019 7 / 19 In the general case, given n + 1 data points we can write down the Lagrange interpolating polynomial of degree n of this form What does '(x) look like? Therefore: P1(x) = '1(x)f (x1) + '2(x)f (x2) where x − x2 x − x1 '1(x) = ;'2(x) = x1 − x2 x2 − x1 In the case of 3 data points (x1; f (x1)); (x2; f (x2)); (x3; f (x3)) P2(x) = '1(x)f (x1) + '2(x)f (x2) + '3(x)f (x3) where: (x − x2)(x − x3) (x − x1)(x − x3) (x − x1)(x − x2) '1(x) = ;'2(x) = ;'3(x) = (x1 − x2)(x1 − x3) (x2 − x1)(x2 − x3) (x3 − x1)(x3 − x2) Interpolation and Curve fitting Spring 2019 7 / 19 What does '(x) look like? Therefore: P1(x) = '1(x)f (x1) + '2(x)f (x2) where x − x2 x − x1 '1(x) = ;'2(x) = x1 − x2 x2 − x1 In the case of 3 data points (x1; f (x1)); (x2; f (x2)); (x3; f (x3)) P2(x) = '1(x)f (x1) + '2(x)f (x2) + '3(x)f (x3) where: (x − x2)(x − x3) (x − x1)(x − x3) (x − x1)(x − x2) '1(x) = ;'2(x) = ;'3(x) = (x1 − x2)(x1 − x3) (x2 − x1)(x2 − x3) (x3 − x1)(x3 − x2) In the general case, given n + 1 data points we can write down the Lagrange interpolating polynomial of degree n of this form Interpolation and Curve fitting Spring 2019 7 / 19 Lagrange interpolating polynomial Lagrange Interpolant 15 10 5 0 y -5 -10 -15 1 2 3 4 5 6 7 8 9 10 x Disadvantage As the polynomial degree increases, the error near the endpoints increases (MA 427) Interpolation and Curve fitting Spring 2019 8 / 19 Cubic spline interpolants A cubic spline interpolant is a piecewise cubic that interpolates the function f at x1; x2; x3;:::; xn and has two continuous derivatives. Why Splines? Useful in applications that require smooth surfaces, e.g. design of airplane parts or cars. Cublic spline Interpolation 9 8 7 6 5 y 4 3 2 1 1 2 3 4 5 6 7 8 9 10 x Interpolation and Curve fitting Spring 2019 9 / 19 The curve can be 1 Polynomials of degree n 2 Trigonometric 3 Exponential Least Squares curve fitting A least squares curve fit can be used to obtain a curve such that the squared distance from each point to the curve is minimized. Interpolation and Curve fitting Spring 2019 10 / 19 Least Squares curve fitting A least squares curve fit can be used to obtain a curve such that the squared distance from each point to the curve is minimized. The curve can be 1 Polynomials of degree n 2 Trigonometric 3 Exponential Interpolation and Curve fitting Spring 2019 10 / 19 Linear Regression Given N data points (xk ; yk ); k = 1;:::; N we seek a line f (x) = mx + b so that the mean square error (MSE): N 2 1 X MSE(m; b) = y − f (x ) N k k k=1 N 2 1 X = y − (mx + b) N k k k=1 We can compute partial derivatives with respect to m and b to find values of m and b that minimize the error. Interpolation and Curve fitting Spring 2019 11 / 19 In MATLAB, the function polyfit performs polynomial regression Usage: a = polyfit(X,Y,N) 1 a - row vector of coefficients of the regression, i.e. 2 X and Y - supplied data points 3 N - polynomial degree a(1)*X^N + a(2)*X^(N-1)+. .+ a(N)*X + a(N+1) To evaluate the polynomial, a at any query points xq Y = polyval(a,xq) Polynomial Regression Define n n−1 f (x) = a1x + a2x + ··· + anx + an+1 that fits the data. Interpolation and Curve fitting Spring 2019 12 / 19 Usage: a = polyfit(X,Y,N) 1 a - row vector of coefficients of the regression, i.e. 2 X and Y - supplied data points 3 N - polynomial degree a(1)*X^N + a(2)*X^(N-1)+. .+ a(N)*X + a(N+1) To evaluate the polynomial, a at any query points xq Y = polyval(a,xq) Polynomial Regression Define n n−1 f (x) = a1x + a2x + ··· + anx + an+1 that fits the data. In MATLAB, the function polyfit performs polynomial regression Interpolation and Curve fitting Spring 2019 12 / 19 Polynomial Regression Define n n−1 f (x) = a1x + a2x + ··· + anx + an+1 that fits the data.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages30 Page
-
File Size-