interpolation
play

Interpolation Sanzheng Qiao Department of Computing and Software - PowerPoint PPT Presentation

Intro Polynomial Piecewise Cubic Spline Software Summary Interpolation Sanzheng Qiao Department of Computing and Software McMaster University January, 2014 Intro Polynomial Piecewise Cubic Spline Software Summary Outline


  1. Intro Polynomial Piecewise Cubic Spline Software Summary Interpolation Sanzheng Qiao Department of Computing and Software McMaster University January, 2014

  2. Intro Polynomial Piecewise Cubic Spline Software Summary Outline Introduction 1 Polynomial Interpolation 2 Piecewise Polynomial Interpolation 3 Natural Cubic Spline 4 Software Packages 5

  3. Intro Polynomial Piecewise Cubic Spline Software Summary Outline Introduction 1 Polynomial Interpolation 2 Piecewise Polynomial Interpolation 3 Natural Cubic Spline 4 Software Packages 5

  4. Intro Polynomial Piecewise Cubic Spline Software Summary Introduction Problem setting: Given ( x 0 , y 0 ) , ( x 1 , y 1 ) , ..., ( x n , y n ) , x 0 < x 1 < · · · x n , for example, a set of measurements, construct a function f : f ( x i ) = y i , i = 0 , 1 , ..., n Desirable properties of f : smooth: analytic and | f ′′ ( x ) | not too large (the first and second derivatives are continuous). simple: polynomial of minimum degree, easy to evaluate.

  5. Intro Polynomial Piecewise Cubic Spline Software Summary Example Measurements of the speed of sound in ocean water 5060 5040 5020 5000 4980 speed (ft/sec) 4960 4940 4920 4900 4880 4860 0 2000 4000 6000 8000 10000 12000 depth (ft)

  6. Intro Polynomial Piecewise Cubic Spline Software Summary Example Interpolation 5060 5040 5020 5000 4980 speed (ft/sec) 4960 4940 4920 4900 4880 4860 0 2000 4000 6000 8000 10000 12000 depth (ft)

  7. Intro Polynomial Piecewise Cubic Spline Software Summary Outline Introduction 1 Polynomial Interpolation 2 Piecewise Polynomial Interpolation 3 Natural Cubic Spline 4 Software Packages 5

  8. Intro Polynomial Piecewise Cubic Spline Software Summary Polynomial Interpolation Advantages: easy to evaluate and differentiate Weierstrass Approximation Theorem: If f is any continuous function on the finite closed interval [a,b], then for every ǫ > 0 there exists a polynomial p n ( x ) of degree n = n ( ǫ ) such that x ∈ [ a , b ] | f ( x ) − p n ( x ) | < ǫ. max

  9. Intro Polynomial Piecewise Cubic Spline Software Summary Polynomial Interpolation Advantages: easy to evaluate and differentiate Weierstrass Approximation Theorem: If f is any continuous function on the finite closed interval [a,b], then for every ǫ > 0 there exists a polynomial p n ( x ) of degree n = n ( ǫ ) such that x ∈ [ a , b ] | f ( x ) − p n ( x ) | < ǫ. max Impractical (degree is often too high)

  10. Intro Polynomial Piecewise Cubic Spline Software Summary A straightforward approach A polynomial of degree n is determined by its n + 1 coefficients.

  11. Intro Polynomial Piecewise Cubic Spline Software Summary A straightforward approach A polynomial of degree n is determined by its n + 1 coefficients. Given ( x 0 , y 0 ) , ..., ( x n , y n ) to be interpolated, we construct the linear system (Vandermonde matrix): x n       1 x 0 · · · a 0 y 0 0 x n 1 x 1 · · · a 1 y 1       1  =  . . .   .   .  . . . . .       · · · . . . . .      x n 1 x n · · · a n y n n solve for the coefficients of the polynomial p n ( y )( x ) = a 0 + a 1 x + · · · + a n x n

  12. Intro Polynomial Piecewise Cubic Spline Software Summary Horner’s rule Evaluating the polynomial: a 0 x 3 + a 1 x 2 + a 2 x + a 3 Horner’s form: (( a 0 x + a 1 ) x + a 2 ) x + a 3

  13. Intro Polynomial Piecewise Cubic Spline Software Summary Horner’s rule Evaluating the polynomial: a 0 x 3 + a 1 x 2 + a 2 x + a 3 Horner’s form: (( a 0 x + a 1 ) x + a 2 ) x + a 3 v = a(0); for (i = 1:n) v = v*x + a(i); end

  14. Intro Polynomial Piecewise Cubic Spline Software Summary Horner’s rule Evaluating the polynomial: a 0 x 3 + a 1 x 2 + a 2 x + a 3 Horner’s form: (( a 0 x + a 1 ) x + a 2 ) x + a 3 v = a(0); for (i = 1:n) v = v*x + a(i); end The optimal (most efficient and accurate) way of evaluating a 0 x n + ... + a n .

  15. Intro Polynomial Piecewise Cubic Spline Software Summary Vandermonde matrix When x 0 , ..., x n are distinct, the Vandermonde matrix is nonsingular. Thus the system has a unique solution (coefficients of the interpolating polynomial).

  16. Intro Polynomial Piecewise Cubic Spline Software Summary Vandermonde matrix When x 0 , ..., x n are distinct, the Vandermonde matrix is nonsingular. Thus the system has a unique solution (coefficients of the interpolating polynomial). Example. Given three points ( 28 , 0 . 4695 ) and ( 30 , 0 . 5000 ) , ( 32 , 0 . 5299 ) we have the system 28 2  1 28   a 0   0 . 4695  30 2  = 1 30 a 1 0 . 5000      32 2 a 2 0 . 5299 1 32 and the solution − 2 . 050 × 10 − 2     a 0  =  . 1 . 960 × 10 − 2 a 1   − 7 . 500 × 10 − 5 a 2 p 2 ( 31 ) = 0 . 5150 ≈ sin ( 30 ◦ )

  17. Intro Polynomial Piecewise Cubic Spline Software Summary Vandermonde matrix problem: The coefficient (Vandermonde) matrix is often ill-conditioned

  18. Intro Polynomial Piecewise Cubic Spline Software Summary Vandermonde matrix problem: The coefficient (Vandermonde) matrix is often ill-conditioned question What is the condition number of the Vandermonde matrix constructed by x i = 2000 + i , i = 0 , 1 , ..., 7?

  19. Intro Polynomial Piecewise Cubic Spline Software Summary Vandermonde matrix problem: The coefficient (Vandermonde) matrix is often ill-conditioned question What is the condition number of the Vandermonde matrix constructed by x i = 2000 + i , i = 0 , 1 , ..., 7? Answer: 1 . 87 × 10 37

  20. Intro Polynomial Piecewise Cubic Spline Software Summary Lagrange form (conceptually simple) Basis polynomials: { l j ( x ) } ( j = 0 , 1 , ..., n ) of degree n such that � 1 , if i = j l j ( x i ) = otherwise 0 , construct x − x i � l j ( x ) = x j − x i i � = j Thus n � p n ( y )( x ) = l j ( x ) y j j = 0

  21. Intro Polynomial Piecewise Cubic Spline Software Summary Example Given three points: ( 28 , 0 . 4695 ) , ( 30 , 0 . 5000 ) , ( 32 , 0 . 5299 ) , construct a second degree interpolating polynomial in the Lagrange form: ( x − 30 )( x − 32 ) p 2 ( x ) = ( 28 − 30 )( 28 − 32 ) 0 . 4695 ( x − 28 )( x − 32 ) + ( 30 − 28 )( 30 − 32 ) 0 . 5000 ( x − 28 )( x − 30 ) + ( 32 − 28 )( 32 − 30 ) 0 . 5299 p 2 ( 31 ) = 0 . 5150 ≈ sin ( 31 ◦ )

  22. Intro Polynomial Piecewise Cubic Spline Software Summary Example Given three points: ( 28 , 0 . 4695 ) , ( 30 , 0 . 5000 ) , ( 32 , 0 . 5299 ) , construct a second degree interpolating polynomial in the Lagrange form: ( x − 30 )( x − 32 ) p 2 ( x ) = ( 28 − 30 )( 28 − 32 ) 0 . 4695 ( x − 28 )( x − 32 ) + ( 30 − 28 )( 30 − 32 ) 0 . 5000 ( x − 28 )( x − 30 ) + ( 32 − 28 )( 32 − 30 ) 0 . 5299 p 2 ( 31 ) = 0 . 5150 ≈ sin ( 31 ◦ ) Expensive to evaluate.

  23. Intro Polynomial Piecewise Cubic Spline Software Summary Dangers of polynomial interpolation An example. Runge’s function (continuous derivatives of all order) 1 y ( x ) = on [ − 1 , 1 ] 1 + 25 x 2 equally spaces x 0 = − 1, x 1 , · · · , x n = 1 Equal Spacing (n = 13) 1 0.5 0 −0.5 −1 −1.5 −2 −2.5 −3 −3.5 −4 −1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1

  24. Intro Polynomial Piecewise Cubic Spline Software Summary Dangers of polynomial interpolation An example. Runge’s function (continuous derivatives of all order) 1 y ( x ) = on [ − 1 , 1 ] 1 + 25 x 2 equally spaces x 0 = − 1, x 1 , · · · , x n = 1 Equal Spacing (n = 13) 1 0.5 0 −0.5 −1 −1.5 −2 −2.5 −3 −3.5 −4 −1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1 It is often best not to use global polynomial interpolation.

  25. Intro Polynomial Piecewise Cubic Spline Software Summary Outline Introduction 1 Polynomial Interpolation 2 Piecewise Polynomial Interpolation 3 Natural Cubic Spline 4 Software Packages 5

  26. Intro Polynomial Piecewise Cubic Spline Software Summary Piecewise Polynomial Interpolation Given the partition α = x 1 < x 2 < · · · < x n = β, interpolate on each [ x i , x i + 1 ] with a low degree polynomial.

  27. Intro Polynomial Piecewise Cubic Spline Software Summary Piecewise Polynomial Interpolation Given the partition α = x 1 < x 2 < · · · < x n = β, interpolate on each [ x i , x i + 1 ] with a low degree polynomial. Linear L i ( z ) = a i + b i ( z − x i ) , z ∈ [ x i , x i + 1 ] b i = y i + 1 − y i a i = y i , , 1 ≤ i ≤ n − 1 x i + 1 − x i

  28. Intro Polynomial Piecewise Cubic Spline Software Summary Algorithm. Piecewise linear interpolation Given vectors x and y with interpolating points, this function returns the piecewise linear interpolation coefficients in the vectors a and b . function [a,b] = pwL(x,y) n = length(x); a = y(1:n-1); b = diff(y)./diff(x);

  29. Intro Polynomial Piecewise Cubic Spline Software Summary Evaluation Given the piecewise linear interpolation L ( z ) represented by the coefficient vectors a , b , how do we evaluate this function at z ∈ [ α, β ] ? First, we locate [ x i , x i + 1 ] such that z ∈ [ x i , x i + 1 ] . Then, we evaluate L ( z ) using L i ( z ) . Search method: binary search, since x i are sorted.

Recommend


More recommend