InterpolationTabulated Data: f x ( ) sin π 4 x · | \ | | . := vx 0 0.5 1 1.5 2 | \ | | | | | | . := i 0 4 .. := vy i f vx i ( ) := vy 0 0.383 0.707 0.924 1 | \ | | | | | | . = 0 1 2 0 0.5 1 vy vx we wish to estimate the y value for an untabulated x value of 0.7 (between 0.5 and 1) Linear Interpolation: x .7 := x 0 vx 1 := y 0 vy 1 := x 1 vx 2 := y 1 vy 2 := y_linear y 0 y 1 y 0 ÷ x 1 x 0 ÷ x x 0 ÷ ( ) · + := y_linear 0.512 = y t f x ( ) := y t 0.522499 = ε t y t y_linear ÷ y t := ε t 1.923 % = MathCAD method: linterp vx vy , .7 , ( ) 0.51245 = Format-Result to 5 decimal places Quadratic Interpolation: x 2 vx 3 := y 2 vy 3 := adding another tabulated point y_quadratic y_linear y 2 y 1 ÷ x 2 x 1 ÷ y 1 y 0 ÷ x 1 x 0 ÷ ÷ x 2 x 0 ÷ x x 0 ÷ ( ) · x x 1 ÷ ( ) · + := y_quadratic 0.525 = ε t y t y_quadratic ÷ y t := ε t 0.55 % = Cubic Interpolation: x 3 vx 4 := y 3 vy 4 := adding another tabulated point fdd1 x i x j , ( ) f x i ( ) f x j ( ) ÷ x i x j ÷ := fdd2 x i x j , x k , ( ) fdd1 x i x j , ( ) fdd1 x j x k , ( ) ÷ x i x k ÷ := fdd3 x 3 x 2 , x 1 , x 0 , ( ) fdd2 x 3 x 2 , x 1 , ( ) fdd2 x 2 x 1 , x 0 , ( ) ÷ x 3 x 0 ÷ := b 0 f x 0 ( ) := b 0 0.383 = b 1 fdd1 x 1 x 0 , ( ) := b 1 0.649 = b 2 fdd2 x 2 x 1 , x 0 , ( ) := b 2 0.215 ÷ = b 3 fdd3 x 3 x 2 , x 1 , x 0 , ( ) := b 3 0.044 ÷ = y_linear b 0 b 1 x x 0 ÷ ( ) · + := y_linear 0.512 = y_quadratic y_linear b 2 x x 0 ÷ ( ) · x x 1 ÷ ( ) · + := y_quadratic 0.525 = y_cubic y_quadratic b 3 x x 0 ÷ ( ) · x x 1 ÷ ( ) · x x 2 ÷ ( ) · + := y_cubic 0.523 = ε t y t y_cubic ÷ y t := ε t 0.145 % = Alternative (full) equation: use CTRL+Enter to continue a line y_cubic b 0 b 1 x x 0 ÷ ( ) · + b 2 x x 0 ÷ ( ) · x x 1 ÷ ( ) · + b 3 x x 0 ÷ ( ) · x x 1 ÷ ( ) · x x 2 ÷ ( ) · + ... := y_cubic 0.52326 = Lagrange Interpolating Polynomials: vx 0.5 1 1.5 2 ( ) T := L vx i , x , n , ( ) L 1 ÷ L L x vx j ÷ ( ) vx i vx j ÷ ( ) · ÷ j i = if j 0 n .. e for := checking some of the Lagrange factors [Li(x)=1 for x=xi; Li(x)=0 at x = xj where j<>i]: L vx 0 , vx 0 , 1 , ( ) 1 = L vx 0 , vx 1 , 2 , ( ) 0 = L vx 2 , vx 2 , 3 , ( ) 1 = L vx 2 , vx 3 , 3 , ( ) 0 = Lagrange_poly n vx , x , ( ) 0 n i L vx i , x , n , ( ) f vx i ( ) · ( ) ¿ = := Lagrange_poly 1 vx , .7 , ( ) 0.51245 = Lagrange_poly 2 vx , .7 , ( ) 0.52537 = Lagrange_poly 3 vx , .7 , ( ) 0.52326 = Finding Coefficients of an Interpolation Polynomial: f x ( ) a 0 a 1 x · + a 2 x 2 · + a 3 x 3 · + = 1 1 1 1 x 0 x 1 x 2 x 3 x 0 ( ) 2 x 1 ( ) 2 x 2 ( ) 2 x 3 ( ) 2 x 0 ( ) 3 x 1 ( ) 3 x 2 ( ) 3 x 3 ( ) 3 ¸ ( ( ( ( ( ( ( ( ¸ a 0 a 1 a 2 a 3 | \ | | | | | | . · y 0 y 1 y 2 y 3 | \ | | | | | | . = x 0.5 1 1.5 2 | \ | | | | | . := i 0 3 .. := y i f x i ( ) := y 0.383 0.707 0.924 1 | \ | | | | | . = j 0 3 .. := A i j , x i ( ) j := A 1 1 1 1 0.5 1 1.5 2 0.25 1 2.25 4 0.125 1 3.375 8 | \ | | | | | . = a 0 a 1 a 2 a 3 | \ | | | | | | . A 1 ÷ y 0 y 1 y 2 y 3 | \ | | | | | | . · := a 0 a 1 a 2 a 3 | \ | | | | | | . 0.016 ÷ 0.851 0.083 ÷ 0.044 ÷ | \ | | | | | . = f x ( ) i a i x i · | \ | . ¿ := f .7 ( ) 0.52326 = same result as Newton and Lagrange cubic interpolations (because the polynomial is unique) Comparing the cubic polynomial fit to the tabulated data and the theoretical function: xr .5 .51 , 2 .. := f t x ( ) sin π 4 x · | \ | | . := 0.5 1 1.5 2 0.2 0.4 0.6 0.8 1 1.2 y f t xr ( ) f xr ( ) x xr , xr , 512 b 1 fdd1 x 1 x 0 b 2 fdd2 x 2 x 1 x 0 b 3 fdd3 x 3 x 2 x 1 x 0 y_linear b 0 b 1 x x 0 y_quadratic y_linear b 2 x x 0 x x 1 y_quadratic 0.383 b 1 0.525 .525 ε t Cubic Interpolation: x 3 vx 4 y 3 vy 4 adding another tabulated point fdd1 x i x j f xi f xj xi xj fdd2 x i x j x k fdd1 x i x j fdd1 x j x k xi xk fdd3 x 3 x 2 x 1 x 0 fdd2 x 3 x 2 x 1 fdd2 x 2 x 1 x 0 x3 x0 b 0 f x 0 b 0 0.55 % y_quadratic 0.044 y_linear 0.649 b 2 0.Quadratic Interpolation: x 2 vx 3 y 2 vy 3 adding another tabulated point y2 y1 y1 y0 x1 x0 x x0 x x1 y_quadratic y_linear y t y_quadratic yt x2 x1 x2 x0 ε t 0.215 b 3 0. 523 y t y_cubic yt ε t ε t 0. Li(x)=0 at x = xj where j<>i]: L vx 0 vx 1 1 0 L vx 0 vx 2 0 1 L vx 2 vx 3 1 2 L vx 2 vx 3 0 3 Lagrange_poly( n vx x ) L(vx i x n)f vxi i 0 n Lagrange_poly( 1 vx .5 2 ) L( vx i x n ) T L1 for j 0 n L L x vxj vxi vxj if j i checking some of the Lagrange factors [Li(x)=1 for x=xi.52326 Lagrange Interpolating Polynomials: vx ( 0.7) 0.7) 0.52326 .52537 Lagrange_poly( 3 vx .145 % Alternative (full) equation: y_cubic b 0 b 1 x x 0 b 2 x x 0 x x 1 b3 x x0 x x1 x x2 use CTRL+Enter to continue a line y_cubic 0.7) 0.y_cubic y_quadratic b 3 x x 0 x x 1 x x 2 y_cubic 0.5 1 1.51245 Lagrange_poly( 2 vx . 5 0.7) 0.707 y 0.044 3 aix i i f ( .924 1 j 0 3 x A i j i j 1 1 A 1 1 0.52326 same result as Newton and Lagrange cubic interpolations (because the polynomial is unique) .083 a 2 a 0.016 a1 0.5 2.375 2 4 8 1 1 1 a0 y0 y a1 1 1 A a2 y2 a y 3 3 f ( x ) a0 0.383 0.Finding Coefficients of an Interpolation Polynomial: f ( x ) = a0 a1 x a2 x a3 x 2 3 1 1 1 1 0.5 1 x 1.5 2 x x x x 0 1 2 3 x0 2 x1 2 x2 2 x3 2 x0 a0 y0 3 x1 a1 y1 = 3 a y x2 2 2 a y 3 3 3 x3 3 i 0 3 y f x i i 0.25 3.25 0.851 0.125 1. 5 .8 0.4 0.Comparing the cubic polynomial fit to the tabulated data and the theoretical function: xr .2 1 y ft( xr) f ( xr) 0.51 2 π ft( x ) sin x 4 1.6 0.5 1 x xr xr 1.2 0.5 2 .