Lagrangian Interpolation Computer 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 Lagrange 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 Lagrangian Interpolation Lagrangian interpolating polynomial is given by n f n ( x) Li ( x) f ( xi ) i 0 where ‘ n ’ in f n (x) stands for the n th order polynomial that approximates the function y f (x) given at (n 1) data points as x0 , y 0 , x1 , y1 ,......, x n 1 , y n 1 , x n , y n , and n Li ( x) j 0 j i x xj xi x j Li (x) is a weighting function that includes a product of (n 1) terms with terms of j i omitted. 5 http://numericalmethods.eng.usf.edu Example A robot arm with a rapid laser scanner is doing a quick quality check on holes drilled in a rectangular plate. The hole centers in the plate that describe the path the arm needs to take are given below. If the laser is traversing from x = 2 to x = 4.25 in a linear path, find the value of y at x = 4 using the Lagrange method for linear interpolation. 6 x (m) y (m) 2 4.25 5.25 7.81 9.2 10.6 7.2 7.1 6.0 5.0 3.5 5.0 Figure 2 Location of holes on the rectangular plate. http://numericalmethods.eng.usf.edu Linear Interpolation 7.2 1 y ( x) Li ( x) y ( xi ) 7.2 7.18 i 0 7.16 L0 ( x) y( x0 ) L1 ( x) y( x1 ) ys f ( range) 7.14 f x desired 7.12 x0 2.00, yx0 7.2 x1 4.25, yx1 7.1 7 7.1 7.1 7.08 5 x s 10 0 0 5 10 x s range x desired http://numericalmethods.eng.usf.edu x s 10 1 Linear Interpolation (contd) x xj x x1 L0 ( x) x0 x1 x x j 0 0 j 1 j 0 1 L1 ( x) j 0 j 1 y ( x) x xj x1 x j x x0 x1 x0 x x0 x x1 y x0 y x1 x0 x1 x1 x0 x 4.25 7.2 x 2.00 7.1, 2.00 x 4.25 2.00 4.25 4.25 2.00 4.00 4.25 4.00 2.00 (7.2) (7.1) 2.00 4.25 4.25 2.00 0.11111(7.2) 0.88889(7.1) 7.1111in. y (4.00) 8 http://numericalmethods.eng.usf.edu Quadratic Interpolation For the second order polynomial interpolation (also called quadratic interpolation), we choose the velocity given by 2 v (t ) Li ( t ) v(t i ) i 0 L0 (t )v (t 0 ) L1 (t ) v( t1 ) L2 (t ) v( t 2 ) 9 http://numericalmethods.eng.usf.edu Example A robot arm with a rapid laser scanner is doing a quick quality check on holes drilled in a rectangular plate. The hole centers in the plate that describe the path the arm needs to take are given below. If the laser is traversing from x = 2 to x = 4.25 in a linear path, find the value of y at x = 4 using the Lagrange method for quadratic interpolation. 10 x (m) y (m) 2 4.25 5.25 7.81 9.2 10.6 7.2 7.1 6.0 5.0 3.5 5.0 Figure 2 Location of holes on the rectangular plate. http://numericalmethods.eng.usf.edu Quadratic Interpolation xo 2.00, yxo 7.2 x1 4.25, yx1 7.1 7.56258 x2 5.25, yx2 6.0 8 7.5 ys 2 L0 ( x) j 0 j 0 x xj x x1 x x 2 x0 x j x0 x1 x0 x 2 x xj x x0 L1 ( x) j 0 x1 x j x1 x0 2 j 1 2 L2 ( x ) j 0 j 2 11 x xj x x 2 x x 2 1 x x0 x x1 x 2 x j x 2 x 0 x 2 x1 f ( range) 7 f x desired 6.5 6 6 2 2 2.5 3 3.5 4 x s range x desired 4.5 5 5.5 5.25 http://numericalmethods.eng.usf.edu Quadratic Interpolation (contd) x x1 x x2 x x0 x x2 x x0 x x1 y( x0 ) y( x1 ) y( x2 ) y( x) x x x x x x x x x x x x 1 0 2 0 1 2 0 2 1 0 1 2 y4.00 4.00 4.254.00 5.25 7.2 4.00 2.004.00 5.25 7.1 4.00 2.004.00 4.25 6.0 2.00 4.252.00 5.25 4.25 2.004.25 5.25 5.25 2.005.25 4.25 0.0427357.2 1.11117.1 0.153856.0 7.2735 in. The absolute relative approximate error a obtained between the results from the first and second order polynomial is 7.2735 7.1111 a 100 7.2735 2.2327 % 12 http://numericalmethods.eng.usf.edu Comparison Table 13 Order of Polynomial 1 2 Location (in.) 7.1111 7.2735 Absolute Relative Approximate Error ---------- 2.2327% http://numericalmethods.eng.usf.edu Example A robot arm with a rapid laser scanner is doing a quick quality check on holes drilled in a rectangular plate. The hole centers in the plate that describe the path the arm needs to take are given below. If the laser is traversing from x = 2 to x = 4.25 in a linear path, find the value of y at x = 4 using a fifth order Lagrange polynomial. x (m) y (m) 2 4.25 5.25 7.81 9.2 10.6 7.2 7.1 6.0 5.0 3.5 5.0 Figure 2 Location of holes on the rectangular plate. 14 http://numericalmethods.eng.usf.edu Fifth Order Interpolation 5 y ( x) Li ( x) y ( xi ) i 0 L0 ( x) y( x0 ) L1 ( x) y( x1 ) L2 ( x) y( x2 ) L3 ( x) y( x3 ) L4 ( x) y( x4 ) L5 ( x) y( x5 ) xo 2.00, yxo 7.2 x1 4.25, yx1 7.1 x2 5.25, yx2 6.0 x3 7.81, yx3 5.0 x4 9.20, yx4 3.5 x5 10.60, yx5 5.0 15 http://numericalmethods.eng.usf.edu Fifth Order Interpolation (contd) 5 L0 ( x) j 0 j 0 5 L1 ( x) j 0 j 1 5 L2 ( x) j 0 j 2 5 L3 ( x) j 0 j 3 5 L4 ( x) j 0 j 4 5 L5 ( x) j 0 j 5 16 x xj x x1 x x2 x x3 x x4 x x5 x0 x j x0 x1 x0 x2 x0 x3 x0 x4 x0 x5 x xj x x0 x x2 x x3 x x4 x x5 x1 x j x1 x0 x1 x2 x1 x3 x1 x4 x1 x5 x xj x x0 x x1 x x3 x x4 x x5 x 2 x j x2 x0 x2 x1 x2 x3 x2 x4 x2 x5 x xj x x0 x x1 x x2 x x4 x x5 x3 x j x3 x0 x3 x1 x3 x2 x3 x4 x3 x5 x xj x x0 x x1 x x2 x x3 x x5 x 4 x j x4 x0 x4 x1 x4 x2 x4 x3 x4 x5 x xj x x0 x x1 x x2 x x3 x x4 x5 x j x5 x0 x5 x1 x5 x2 x5 x3 x5 x4 http://numericalmethods.eng.usf.edu Fifth Order Polynomial (contd) x x1 x x2 x x3 x x4 x x5 y ( x0 ) y ( x) x0 x1 x0 x2 x0 x3 x0 x4 x0 x5 x x0 x x2 x x3 x x4 x x5 y ( x1 ) x1 x0 x1 x2 x1 x3 x1 x4 x1 x5 x x0 x x1 x x3 x x4 x x5 y ( x2 ) x2 x0 x2 x1 x2 x3 x2 x4 x2 x5 x x0 x x1 x x2 x x4 x x5 y ( x3 ) x3 x0 x3 x1 x3 x2 x3 x4 x3 x5 x x0 x x1 x x2 x x3 x x5 y ( x4 ) x4 x0 x4 x1 x4 x2 x4 x3 x4 x5 x x0 x x1 x x2 x x3 x x4 y ( x5 ) x5 x0 x5 x1 x5 x2 x5 x3 x5 x4 17 http://numericalmethods.eng.usf.edu Fifth Order Polynomial (contd) ( x 4.25)(x 5.25)(x 7.81)(x 9.20)(x 10.60) ( 7.2 ) (2.00 4.25)(2.00 5.25)(2.00 7.81)(2.00 9.20)(2.00 10.60) ( x 2.00)(x 5.25)(x 7.81)(x 9.20)(x 10.60) (7.1) (4.25 2.00)(4.25 5.25)(4.25 7.81)(4.25 9.20)(4.25 10.60) ( x 2.00)(x 4.25)(x 7.81)(x 9.20)(x 10.60) ( 6.0) (5.25 2.00)(5.25 4.25)(5.25 7.81)(5.25 9.20)(5.25 10.60) ( x 2.00)(x 4.25)(x 5.25)(x 9.20)(x 10.60) (5.0) (7.81 2.00)(7.81 4.25)(7.81 5.25)(7.81 9.20)(7.81 10.60) ( x 2.00)(x 4.25)(x 5.25)(x 7.81)(x 10.60) (3.5) (9.20 2.00)(9.20 4.25)(9.20 5.25)(9.20 7.81)(9.20 10.60) ( x 2.00)(x 4.25)(x 5.25)(x 7.81)(x 9.20) (5.0) (10.60 2.00)(10.60 4.25)(10.60 5.25)(10.60 7.81)(10.60 9.20) y ( x) 18 http://numericalmethods.eng.usf.edu Fifth Order Polynomial (contd) x 5 37.11x 4 536.77x 3 3773.2 x 2 12862x 16994 yx 365.38 x 5 34.86x 4 462.83x 3 2879.7 x 2 8169.5 x 7997.1 35.461 x 5 33.86x 4 433.22x 3 2572.3 x 2 6903.5 x 6473.9 29.304 x 5 31.3 x 4 366.53x 3 1984.1x 2 4912.4 x 4351.8 41.069 x 5 29.91x 4 335.81x 3 1757.2 x 2 4241.6 x 3694.3 78.273 x 5 28.51x 4 308.78x 3 1573.7 x 2 3727.5 x 3206.4 228.24 y( x) 30.898 41.344x 15.855x 2 2.7862x 3 0.23091x 4 0.0072923x 5 , 2 x 10.6 19 http://numericalmethods.eng.usf.edu Fifth Order Polynomial (contd) y( x) 30.900 41.351x 15.858x 2 2.7865x 3 0.23093x 4 0.0072929x 5 , 2 x 10.6 20 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/lagrange_ method.html THE END http://numericalmethods.eng.usf.edu