MATHCAD Interpolation

April 4, 2018 | Author: Anonymous | Category: Documents
Report this link


Description

Interpolation Tabulated 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 ji]: 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 ,


Comments

Copyright © 2024 UPDOCS Inc.