Transcript PPT
Spline Interpolation Method Industrial Engineering Majors Authors: Autar Kaw, Jai Paul http://numericalmethods.eng.usf.edu Transforming Numerical Methods Education for STEM Undergraduates http://numericalmethods.eng.usf.edu 1 Spline Method of Interpolation http://numericalmethods.eng.usf.edu What is Interpolation ? Given (x0,y0), (x1,y1), …… (xn,yn), find the value of ‘y’ at a value of ‘x’ that is not given. 3 http://numericalmethods.eng.usf.edu Interpolants Polynomials are the most common choice of interpolants because they are easy to: Evaluate Differentiate, and Integrate. 4 http://numericalmethods.eng.usf.edu Why Splines ? 1 f ( x) 1 25 x 2 Table : Six equidistantly spaced points in [-1, 1] x 1 1 25 x 2 -1.0 0.038461 -0.6 0.1 -0.2 0.5 0.2 0.5 0.6 0.1 1.0 5 y 0.038461 Figure : 5th order polynomial vs. exact function http://numericalmethods.eng.usf.edu Why Splines ? 1.2 0.8 y 0.4 0 -1 -0.5 0 0.5 1 -0.4 -0.8 x 19th Order Polynomial f (x) 5th Order Polynomial Figure : Higher order polynomial interpolation is a bad idea 6 http://numericalmethods.eng.usf.edu Linear Interpolation Given x0 , y0 , x1 , y1 ,......, x n 1 , y n1 x n , y n , fit linear splines to the data. This simply involves forming the consecutive data through straight lines. So if the above data is given in an ascending order, the linear splines are given by yi f ( xi ) Figure : Linear splines 7 http://numericalmethods.eng.usf.edu Linear Interpolation (contd) f ( x ) f ( x0 ) f ( x1 ) f ( x 0 ) ( x x 0 ), x1 x 0 x 0 x x1 f ( x1 ) f ( x 2 ) f ( x1 ) ( x x1 ), x2 x1 x1 x x 2 . . . f ( x n 1 ) f ( x n ) f ( x n 1 ) ( x x n 1 ), x n 1 x x n x n x n 1 Note the terms of f ( xi ) f ( x i 1 ) xi x i 1 in the above function are simply slopes between xi 1 and x i . 8 http://numericalmethods.eng.usf.edu Example A curve needs to be fit through the given points to fabricate the cam. If the cam follows a straight line profile between x = 1.28 to x = 0.66, what is the value of y at x=1.1 ? Find using linear spline interpolation. 9 x (in.) y (in.) 2.20 0.00 1.28 0.88 0.66 1.14 0.00 1.20 –0.60 1.04 –1.04 0.60 –1.20 0.00 Cam Profile 4 3 5 2 1.4 1.2 1 6 0.8 y Point 1 2 3 4 5 6 7 Y 7 0.6 1 0.4 X 0.2 0 -2 -1 0 1 2 x http://numericalmethods.eng.usf.edu 3 Linear Interpolation x0 1.28, y( x0 ) 0.88 x1 0.66, y( x1 ) 1.14 y( x1 ) y( x0 ) y ( x) y ( x0 ) ( x x0 ) x1 x0 1.14 1.1 1.05 ys f ( range) f x desired 1.14 0.88 0.88 ( x 1.28) 0.66 1.28 y( x) 0.88 0.41935( x 1.28) 0.66 x 1.28 1 0.95 0.9 0.88 0.85 5 x s 10 0 0 5 x s range x desired At x 1.10, y (1.10) 0.88 0.41935(1.10 1.28) 0.95548 in. 10 http://numericalmethods.eng.usf.edu 10 x s 10 1 Linear Interpolation Find the cam profile using linear splines. The first linear spline connects x 1.20 and x 1.04 : y ( x) 0.00 0.60 0.00 ( x 1.20) 1.04 1.20 y ( x) 3.75( x 1.20) 1.20 x 1.04 Similarly, 11 y ( x) x 1.64, 1.04 x 0.60 y ( x) 1.04 0.26667( x 0.60), 0.60 x 0.00 y ( x) 1.20 0.090909 x, 0.00 x 0.66 y ( x) 1.14 0.41935( x 0.66), 0.66 x 1.28 y ( x) 0.88 0.95652( x 1.28), 1.28 x 2.20 http://numericalmethods.eng.usf.edu Linear Interpolation y ( x ) 3.75( x 1.20) 1.20 x 1.04 y ( x ) x 1.64, 1.04 x 0.60 y ( x ) 1.04 0.26667( x 0.60), 0.60 x 0.00 y ( x ) 1.20 0.090909 x, 0.00 x 0.66 y ( x ) 1.14 0.41935( x 0.66), 0.66 x 1.28 y ( x ) 0.88 0.95652( x 1.28), 1.28 x 2.20 12 http://numericalmethods.eng.usf.edu Quadratic Interpolation Given x0 , y0 , x1 , y1 ,......, x n 1 , y n 1 , x n , y n , fit quadratic splines through the data. The splines are given by f ( x ) a1 x 2 b1 x c1 , a 2 x 2 b2 x c2 , x 0 x x1 x1 x x 2 . . . a n x 2 bn x cn , x n 1 x x n Find a i , bi , ci , i 1, 2, …, n 13 http://numericalmethods.eng.usf.edu Quadratic Interpolation (contd) Each quadratic spline goes through two consecutive data points a1 x 0 b1 x 0 c1 f ( x0 ) 2 a1 x1 2 b1 x1 c1 f ( x1 ) . . . a i xi 1 bi xi 1 ci f ( xi 1 ) 2 a i xi bi xi c i f ( xi ) 2 . . . a n x n 1 bn x n 1 c n f ( xn 1 ) 2 a n x n bn xn cn f ( x n ) 2 14 This condition gives 2n equations http://numericalmethods.eng.usf.edu Quadratic Splines (contd) The first derivatives of two quadratic splines are continuous at the interior points. For example, the derivative of the first spline a1 x 2 b1 x c1 is 2 a1 x b1 The derivative of the second spline a 2 x 2 b2 x c 2 is 2 a2 x b2 and the two are equal at x x1 giving 2 a1 x1 b1 2a 2 x1 b2 2 a1 x1 b1 2a 2 x1 b2 0 15 http://numericalmethods.eng.usf.edu Quadratic Splines (contd) Similarly at the other interior points, 2a 2 x 2 b2 2a3 x 2 b3 0 . . . 2ai xi bi 2ai 1 xi bi 1 0 . . . 2a n 1 x n 1 bn 1 2a n x n 1 bn 0 We have (n-1) such equations. The total number of equations is (2n) (n 1) (3n 1) . We can assume that the first spline is linear, that is a1 0 16 http://numericalmethods.eng.usf.edu Quadratic Splines (contd) This gives us ‘3n’ equations and ‘3n’ unknowns. Once we find the ‘3n’ constants, we can find the function at any value of ‘x’ using the splines, f ( x) a1 x 2 b1 x c1 , a 2 x 2 b2 x c 2 , x0 x x1 x1 x x 2 . . . a n x 2 bn x c n , 17 x n 1 x x n http://numericalmethods.eng.usf.edu Example A curve needs to be fit through the given points to fabricate the cam. If the cam follows a straight line profile between x = 1.28 to x = 0.66, what is the value of y at x=1.1 ? Find using a quadratic spline interpolation. 18 x (in.) y (in.) 2.20 0.00 1.28 0.88 0.66 1.14 0.00 1.20 –0.60 1.04 –1.04 0.60 –1.20 0.00 Cam Profile 4 3 5 2 1.4 1.2 1 6 0.8 y Point 1 2 3 4 5 6 7 Y 7 0.6 1 0.4 X 0.2 0 -2 -1 0 1 2 x http://numericalmethods.eng.usf.edu 3 Solution Since there are seven data points, six quadratic splines pass through them. 19 y( x) a1 x 2 b1 x c1 , 1.20 x 1.04 a 2 x 2 b2 x c2 , 1.04 x 0.60 a3 x 2 b3 x c3 , 0.60 x 0.00 a 4 x 2 b4 x c4 , 0.00 x 0.66 a5 x 2 b5 x c5 , 0.66 x 1.28 a 6 x 2 b6 x c6 , 1.28 x 2.20 http://numericalmethods.eng.usf.edu Solution (contd) Setting up the equations Each quadratic spline passes through two consecutive data points giving a1 x 2 b1 x c1 passes through x = −1.20 and x = −1.04, a1 (1.20) 2 b1 (1.20) c1 0.00 (1) a1 (1.04) 2 b1 (1.04) c1 0.60 (2) Similarly, 20 a2 (1.04) 2 b2 (1.04) c2 0.60 (3) a2 (0.60) 2 b2 (0.60) c2 1.04 (4) a3 (0.60) 2 b3 (0.60) c3 1.04 (5) a3 (0.00) 2 b3 (0.00) c3 1.20 (6) a4 (0.00) 2 b4 (0.00) c4 1.20 (7) a4 (0.66) 2 b4 (0.66) c4 1.14 (8) a5 (0.66) 2 b5 (0.66) c5 1.14 (9) a5 (1.28) 2 b5 (1.28) c5 0.88 (10) a 6 (1.28) 2 b6 (1.28) c6 0.88 (11) a 6 (2.20) 2 b6 (2.20) c6 0.00 (12) http://numericalmethods.eng.usf.edu Solution (contd) Quadratic splines have continuous derivatives at the interior data points At x = −1.04 2a1 (1.04) b1 2a2 (1.04) b2 0 (13) 2a2 (0.60) b2 2a3 (0.60) b3 0 (14) 2a3 (0.00) b3 2a4 (0.00) b4 0 (15) 2a4 (0.66) b4 2a5 (0.66) b5 0 (16) 2a5 (1.28) b5 2a6 (1.28) b6 0 (17) At x = −0.60 At x = 0.00 At x = 0.66 At x = 1.28 Assuming the first spline a1 x 2 b1 x c1 is linear, a1 0 21 (18) http://numericalmethods.eng.usf.edu Solution (contd) 1.2 1.44 1.0816 1.04 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.08 1 0 0 0 0 0 0 0 0 1 0 22 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1.0816 1.04 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0.36 0.6 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.36 0 0 0.6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0.4356 0.66 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.4356 0.66 1 0 1.6384 1.28 1 0 0 0 0 0 2.08 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.2 0 1 0 0 0 1.2 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.32 0 1 0 0 0 1.32 2.56 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 a1 0.00 0 0 0 b1 0.60 0 0 0 c1 0.60 0 0 0 a2 1.04 0 0 0 b2 1.04 0 0 0 c2 1.20 0 0 0 a3 1.20 0 0 0 b3 1.14 0 0 0 c3 1.14 0 0 0 a4 0.88 1.6384 1.28 1 b4 0.88 4.84 2.2 1 c4 0.00 0 0 0 a5 0 0 0 0 b5 0 0 0 0 c5 0 0 0 0 a6 0 2.56 1 0 b6 0 0 0 0 c6 0 0 0 http://numericalmethods.eng.usf.edu Solution (contd) Solving the above 18 equations gives the 18 unknowns as i 1 2 3 4 5 6 23 ai 0 −6.25 3.3611 −3.5973 3.2997 −2.8076 bi ci 3.75 4.5 −9.25 −2.26 2.2833 1.2 2.2833 1.2 −6.8207 4.2043 8.8138 −5.8018 http://numericalmethods.eng.usf.edu Solution (contd) Therefore, the splines are given by y ( x) 3.75 x 4.5, 1.20 x 1.04 6.25 x 2 9.25 x 2.26, 1.04 x 0.60 3.3611x 2 2.2833x 1.2, 0.60 x 0.00 3.5973x 2 2.2833x 1.2, 0.00 x 0.66 3.2997 x 2 6.8207 x 4.2043, 0.66 x 1.28 2.8076 x 2 8.8138 x 5.8018, 1.28 x 2.20 24 http://numericalmethods.eng.usf.edu Comparison 1.6 1.5 y f quadratic( range) f quadratic x desired 1 f linear( range) f linear x desired 0.5 f ( range) f x desired y 0 0.05 h 0 1 x0 0.05 w 0.5 0 0.5 1 1.5 x range x desired range x desired range x desired 2 xl 0.05 w Figure : Cam profile as defined by linear and quadratic splines (dotted line represents sixth order polynomial interpolant) 25 http://numericalmethods.eng.usf.edu Additional Resources For all resources on this topic such as digital audiovisual lectures, primers, textbook chapters, multiple-choice tests, worksheets in MATLAB, MATHEMATICA, MathCad and MAPLE, blogs, related physical problems, please visit http://numericalmethods.eng.usf.edu/topics/spline_met hod.html THE END http://numericalmethods.eng.usf.edu