CS321-001 Introduction to Numerical Methods Lecture 3 Interpolation and Numerical Differentiation Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506-0633 Polynomial Interpolation Given a set of discrete values, how can we estimate other values between these data The method that we will use is called polynomial interpolation. We assume the data we had are from the evaluation of a smooth function. We may be able to use a polynomial p(x) to approximate this function, at least locally. A condition: the polynomial p(x) takes the given values at the given points (nodes), i.e., p(xi) = yi with 0 ≤ i ≤ n. The polynomial is said to interpolate the table, since we do not know the function. 2 Polynomial Interpolation Note that all the points are passed through by the curve 3 Polynomial Interpolation We do not know the original function, the interpolation may not be accurate 4 Order of Interpolating Polynomial A polynomial of degree 0, a constant function, interpolates one set of data If we have two sets of data, we can have an interpolating polynomial of degree 1, a linear function x x1 x x0 p(x) y0 y1 x0 x1 x1 x0 y1 y0 y0 (x x0 ) x1 x0 Review carefully if the interpolation condition is satisfied Interpolating polynomials can be written in several forms, the most well known ones are the Lagrange form and Newton form. Each has some advantages 5 Lagrange Form For a set of fixed nodes x0, x1, …, xn, the cardinal functions, l0, l1,…, ln, are defined as 0 if i j li (x j ) ij 1 if i j We can interpolate any function f(x) by the Lagrange form of the interpolating polynomial of degree ≤ n n pn (x) li (x) f (xi ) i0 Note that li(x) is of order n, so pn(x) is of order ≤ n, and n pn (x j ) li (x j )f(xi ) l j (x j )f(x j ) f(x j ) i0 The (point exact) interpolation condition is satisfied 6 Cardinal Functions The cardinal function is n x x j li (x) (0 i n) ji, j0 xi x j What it looks like x x0 x x1 li (x) xi x0 xi x1 x xi1 x xi1 xi xi1 xi xi1 x xn xi xn Note that li (x j ) 0, for i j and li (xi ) 1 7 An Example Find the interpolating polynomial for this table Lagrange form (x 1)(x 1) l (x) (x 1)(x 1) 0 (0 1)(0 1) (x 0)(x 1) 1 l (x) x(x 1) 1 (1 0)(1 1) 2 (x 0)(x 1) 1 l (x) x(x 1) 2 (1 0)(1 1) 2 The interpolating polynomial is 3 15 p (x) 5(x 1)(x 1) x(x 1) x(x 1) 2 2 2 8 Five Lagrange Basis Polynomials These are the 5 Lagrange basis polynomials for N=5 9 Representation by Lagrange Polynomials Five weighted polynomials and their sum (red line) for a set of 5 random samples (red points) 10 Step by Step Construction For any table of data, we can construct a Lagrange interpolating polynomial. Its evaluation is a little bit costly, but we can always do that. The existence of the interpolating polynomial is guaranteed Can we construct the interpolating polynomial step by step, or if we discover some new data, can we add those data to make the interpolation more accurate? We can use Newton form of the interpolating polynomial Let pk(x) be an interpolating polynomial for the data set {(xi,yi)} with 0 ≤ i ≤ k such that pk(xi) = yi 11 Newton Form - Cont. We want to add another data (xk+1, yk+1) to have a new interpolating polynomial pk+1(x) such that pk+1(xi) = yi for 0 ≤ i ≤ (k + 1). Let pk1 (x) pk (x) c(x x0 )(x x1 )(x xk ) where c is an undetermined constant Sincepk1(xk1 ) yk1 , we have pk (xk1 ) c(xk1 x0 )(xk1 x1 ) (xk1 xk ) yk1 We can solve this equation for c, with the condition that x0, x1, …, xk+1 are all distinct y p (x ) c k1 k k1 (xk1 x0 )(xk1 x1 )(xk1 xk ) 12 Newton Polynomial Interpolation 13 Uniqueness of Polynomial Is the interpolating polynomial unique? If p and q are interpolating polynomials for the data set {(xi,yi)} for 0 ≤ i ≤ n such that p(xi) = q(xi) = yi Then the polynomial r(x) = p(x) – q(x) of degree at most n is zero at x0, x1, …, xn. Note that a polynomial of degree n can have at most n roots, we must have r(x) = 0, or p – q = 0. Hence p = q The interpolating polynomial is unique It may be written in different forms 14 An Example Find the interpolating polynomial for this table Lagrange form (x 1)(x 1) l (x) (x 1)(x 1) 0 (0 1)(0 1) (x 0)(x 1) 1 l (x) x(x 1) 1 (1 0)(1 1) 2 (x 0)(x 1) 1 l (x) x(x 1) 2 (1 0)(1 1) 2 The interpolating polynomial is 3 15 p (x) 5(x 1)(x 1) x(x 1) x(x 1) 2 2 2 15 Newton Form The zeroth order polynomial is p0 (x) 5 Let the 1st order interpolating polynomial be p1 (x) p0 c(x x0 ) 5 c(x 0) We want p1(x1) = -3, hence -5 + c(1 – 0) = -3, we have c = 2, it follows that p1 (x) 5 2x Let the 2nd order interpolating polynomial be p2 (x) p1(x) c(x x0 )(x x1 ) Put p2(-1) = -15, i.e., -5+2(-1) + c(-1 – 0)(-1 – 1) = -15. We have c = -4. The Newton form of the interpolating polynomial is p2 (x) 5 2x 4x(x 1) 16 Nested Form For easy programming and efficient computation, we can write Newton form of the interpolating polynomial in nested form p(x) a0 a1[(x x0 )] a2[(x x0 )(x x1 )] a3[(x x0 )(x x1 )(x x2 )] an[(x x0 )(x x1 )(x xn1 )] Or, using standard product notations as n i1 p(x) a0 ai (x x j ) i1 j1 Using successive factorization, the nested form is p(x) a0 (x x0 )(a1 (x x1 )(a2 (x xn1 )an ))) (((an (x xn1 ) an1 )(x xn2 ) an2 ))(x x0 ) a0 17 Computation Procedure To evaluate p(x) for a given x, we start from the innermost parentheses, forming successively some intermediate quantities v0 an v1 v0 (x xn1 ) an1 v2 v1(x xn2 ) an2 vi vi1(x xni ) ani vn vn1 (x x0 ) a0 A pseudocode is real array (ai )0:n , (xi )0:n integer i, n real x, v v an for i n 1 to 0 step -1 do v v(x xi ) ai end for 18 Divided Difference The coefficients ai in Newton form of the interpolating polynomial need to be computed. A notation is introduced to facilitate such computation ak f[x0,x1,,xk ] which is called the divided difference of order k for f Newton form interpolating polynomial is pn (x) a0 a1 (x x0 ) a2 (x x0 )(x x1 ) an (x x0 )(x xn1 ) Or written in a compact form n i1 pn (x) ai (x x j ) i0 j0 with the convention 1 (x x j ) 1 j0 19 Computing Coefficients ai We want pn(xi) = f(xi). So we have f (x0 ) a0 f (x1) a0 a1(x1 x0 ) f (x2 ) a0 a1(x2 x0 ) a2 (x2 x0 )(x2 x1) The solution of this system is a0 f (x0 ) f (x1 ) a0 a1 x1 x0 f (x ) f (x ) 1 0 x1 x0 The divided difference of order 1 is f (x1 ) f (x0 ) f [x0 , x1 ] x1 x0 k Note that f[x0, x1,…, xk] is the coefficient of x in the polynomial pk of degree ≤ k 20 Computing Coefficients – Cont. f (x2 ) a0 a1 (x2 x0 ) a2 (x2 x0 )(x2 x1 ) f (x ) f [x ] f [x , x ](x x ) 2 0 0 1 2 0 (x2 x0 )(x2 x1 ) f [x0 , x1 , x2 ] In general, we have f [x0 , x1 ,, xk ] k1 i1 f (xk ) i0 f [x0 , x1 ,, xi ] j0 (xk x j ) k1 j0 (xk x j ) Computational algorithm •Set f[x0] = f(x0) •For k = 1, 2,…, n, compute f[x0, x1,…, xk] using the above equation 21 Recursive Formula The divided difference has a recursive formula f[x0 , x1,, x k ] f[x1, x 2 ,, x k ] f[x0, x1,, x k1] x k x 0 Proof: k f[x0, x1,…, xk] is the coefficient of x in the polynomial pk of degree ≤ k, which interpolates f at x0, x1,…, xk k-1 f[x1, x2,…, xk] is the coefficient of x in the polynomial qk-1 of degree ≤ (k – 1), which interpolates f at x1, x2,…, xk k-1 f[x0, x1,…, xk-1] is the coefficient of x in the polynomial pk-1of degree ≤ (k – 1), which interpolates f at x0, x1,…, xk-1 22 Recursive Formula - Proof We have x xk pk (x) qk1(x) [qk1 (x) pk1(x)] xk x0 To prove this identity, it suffices to show that it holds at (k + 1) different points, since the left-hand side and the right-hand side are polynomials of degree ≤ k. Note that the left-hand side is pk(xi) = f(xi) for i = 0, 1,…, k Check the right-hand side at point x0 x0 xk qk1 (x0 ) [qk1 (x0 ) pk1(x0 )] xk x0 qk1 (x0 ) [qk1(x0 ) pk1(x0 )] pk1(x0 ) f (x0 ) 23 Formula Proof - Cont.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages52 Page
-
File Size-