
CE30125 - Lecture 3 LECTURE 3 LAGRANGE INTERPOLATION th • Fit N + 1 points with an N degree polynomial g(x) f 2 f(x) f f 3 f4 1 f f0 N x0 x1 x2 x3 x4 ... xN •fx = exact function of which only N + 1 discrete values are known and used to estab- lish an interpolating or approximating function gx •gx = approximating or interpolating function. This function will pass through all specified N + 1 interpolation points (also referred to as data points or nodes). p. 3.1 CE30125 - Lecture 3 • The interpolation points or nodes are given as: xo fxo fo x1 fx1 f1 x2 fx2 f2 : xN fxN fN th • There exists only one N degree polynomial that passes through a given set of N + 1 points. It’s form is (expressed as a power series): 2 3 N gx= ao +++++a1xa2x a3x aNx where ai = unknown coefficients, i = 0 N (N + 1 coefficients). • No matter how we derive the Nth degree polynomial, • Fitting power series • Lagrange interpolating functions • Newton forward or backward interpolation The resulting polynomial will always be the same! p. 3.2 CE30125 - Lecture 3 Power Series Fitting to Define Lagrange Interpolation •gx must match fx at the selected data points 2 N gxo = fo ao ++++a1xo a2xo aNxo = fo 2 N gx1 = f1 ao ++a1x1 a2x1 ++ aNx1 = f1 : : 2 N gxN = fN ao + a1xN +++a2xN aNxN = fN • Solve set of simultaneous equations 1 x x2 xN o o o ao fo 2 N a f 1 x1 x1 x1 1 = 1 : : 2 N aN fN 1 xN xN xN • It is relatively computationally costly to solve the coefficients of the interpolating func- tion gx (i.e. you need to program a solution to these equations). p. 3.3 CE30125 - Lecture 3 Lagrange Interpolation Using Basis Functions • We note that in general gxi = fi •Let N gx= fi Vix i = 0 where Vix = polynomial of degree N associated with each node i such that 0 i j Vixj 1 i = j • For example if we have 5 interpolation points (or nodes) gx3 = foVox3 ++++f1V1x3 f2V2x3 f3V3x3 f4V4x3 Using the definition for Vixj : V0x3 = 0 ; V1x3 = 0 ; V2x3 = 0 ; V3x3 = 1 ; V4x3 = 0 ,we have: gx3 = f3 p. 3.4 CE30125 - Lecture 3 • How do we construct Vix ? • Degree N • Roots at xox1 x2 xi – 1 xi + 1 xN (at all nodes except xi ) • Vixi = 1 •Let Wix = xx– o xx– 1 xx– 2 xx– i – 1 xx– i + 1 xx– N • The function Wi is such that we do have the required roots, i.e. it equals zero at nodes xox1 x2 ... , xN except at node xi • Degree of Wix is N • However Wix in the form presented will not equal to unity at xi • We normalize Wix and define the Lagrange basis functions Vix xx– o xx– 1 xx– 2 xx– i – 1 xx– i + 1 xx– N Vix = -------------------------------------------------------------------------------------------------------------------------------------------------------- xi – xo xi – x1 xi – x2 xi – xi – 1 xi – xi + 1 xi – xN p. 3.5 CE30125 - Lecture 3 • Now we have Vix such that Vixi equals: xi – xo xi – x1 xi – x2 xi – xi – 1 1 xi – xi + 1 xi – xN Vixi = ------------------------------------------------------------------------------------------------------------------------------------------------------------ xi – xo xi – x1 xi – x2 xi – xi – 1 xi – xi + 1 xi – xN Vixi = 1 • We also satisfy Vixj = 0 for ij x2 – xo 1 x2 – x2 x2 – x3 x2 – xN e.g. V1x2 ==---------------------------------------------------------------------------------------------------------0 x1 – xo 1 x1 – x2 x1 – x3 x1 – xN • The general form of the interpolating function gx with the specified form of Vix is: N gx= fiVix i = 0 • The sum of polynomials of degree N is also polynomial of degree N • gx is equivalent to fitting the power series and computing coefficients ao aN . p. 3.6 CE30125 - Lecture 3 Lagrange Linear Interpolation Using Basis Functions • Linear Lagrange N = 1 is the simplest form of Lagrange Interpolation 1 gx= fiVix i = 0 gx= foVox + f1V1x where xx– 1 x1 – x xx– o Vox ==--------------------- --------------------- and V1x = --------------------- xo – x1 x1 – xo x1 – xo V (x) V1(x) 1.0 0 (x) x0 x1 p. 3.7 CE30125 - Lecture 3 Example • Given the following data: xo = 2 fo = 1.5 x1 = 5 f1 = 4.0 Find the linear interpolating function gx • Lagrange basis functions are: 5 – x x – 2 V x = ----------- and V x = ----------- o 3 1 3 • Interpolating function g(x) is: gx= 1.5Vox + 4.0V1x p. 3.8 CE30125 - Lecture 3 4 2 1.5 V0 (x) x x0 = 2 x1 = 5 4 4.0 V (x) 2 1 x x0 = 2 x1 = 5 g(x) = 1.5 V0(x) + 4.0V1(x) x0 = 2 x1 = 5 p. 3.9 CE30125 - Lecture 3 Lagrange Quadratic Interpolation Using Basis Functions • For quadratic Lagrange interpolation, N=2 2 gx= fi Vix i = 0 gx= foVox ++f1V1x f2V2x where xx– 1 xx– 2 Vox = ------------------------------------------ xo – x1 xo – x2 xx– o xx– 2 V1x = ------------------------------------------ x1 – xo x1 – x2 xx– o xx– 1 V2x = ------------------------------------------ x2 – xo x2 – x1 p. 3.10 CE30125 - Lecture 3 V0 (x) V1(x) V2(x) 1.0 x x0 x1 x2 • Note that the location of the roots of V0x , V1x and V2x are defined such that the basic premise of interpolation is satisfied, namely that gxi = fi . Thus: gxo ==Voxo fo ++V1xo f1 V2xo f2 f0 gx1 ==Vox1 fo ++V1x1 f1 V2x1 f2 f1 gx2 ==Vox2 fo ++V1x2 f1 V2x2 f2 f2 p. 3.11 CE30125 - Lecture 3 Example • Given the following data: xo =3 fo = 1 x1 = 4 f1 = 2 x2 = 5 f2 = 4 Find the quadratic interpolating function gx • Lagrange basis functions are x – 4 x – 5 V x = ---------------------------------- o 34– 35– x – 3 x – 5 V x = ---------------------------------- 1 43– 45– x – 3 x – 4 V x = ---------------------------------- 2 53– 54– • Interpolating function g(x) is: gx= 1.0Vox ++2.0V1x 4.0V2x p. 3.12 CE30125 - Lecture 3 1.0 1.0 V0 (x) x x0 = 3 x2 = 5 x1 = 4 2.0 2.0 V1(x) x x0 = 3 x1 = 4 x2 = 5 4.0 4.0 V2(x) x x0 = 3 x1 = 4 x2 = 5 g(x) = 1.0 V0(x) + 2.0V1(x) + 4.0V2(x) 4.0 x0 = 3 x1 = 4 x2 = 5 p. 3.13 CE30125 - Lecture 3 Lagrange Cubic Interpolation Using Basis Functions • For Cubic Lagrange interpolation, N=3 Example • Consider the following table of functional values (generated with fx= lnx ) i xi fi 0 0.40 -0.916291 1 0.50 -0.693147 2 0.70 -0.356675 3 0.80 -0.223144 • Find g0.60 as: xx– 1 xx– 2 xx– 3 xx– o xx– 2 xx– 3 gx= fo---------------------------------------------------------------- + f1---------------------------------------------------------------- xo – x1 xo – x2 xo – x3 x1 – xo x1 – x2 x1 – x3 xx– o xx– 1 xx– 3 xx– o xx– 1 xx– 2 ++f2---------------------------------------------------------------- f3---------------------------------------------------------------- x2 – xo x2 – x1 x2 – x3 x3 – xo x3 – x1 x3 – x2 p. 3.14 CE30125 - Lecture 3 0.60– 0.50 0.60– 0.70 0.60– 0.80 g0.60 = –0.916291 ------------------------------------------------------------------------------------------------ 0.40– 0.50 0.40– 0.70 0.40– 0.80 0.60– 0.40 0.60– 0.70 0.60– 0.80 –0.693147 ------------------------------------------------------------------------------------------------ 0.50– 0.40 0.50– 0.70 0.50– 0.80 0.60– 0.40 0.60– 0.50 0.60– 0.80 –0.356675 ------------------------------------------------------------------------------------------------ 0.70– 0.40 0.70– 0.50 0.70– 0.80 0.60– 0.40 0.60– 0.50 0.60– 0.70 –0.223144 ------------------------------------------------------------------------------------------------ 0.80– 0.40 0.80– 0.50 0.80– 0.70 g0.60 = –0.509976 p. 3.15 CE30125 - Lecture 3 Errors Associated with Lagrange Interpolation • Using Taylor series analysis, the error can be shown to be given by: ex= fx– gx N + 1 ex= Lxf xo xN where N + 1 th f = N + 1 derivative of f w.r.t. x evaluated at xx– o xx– 1 xx– N th Lx==--------------------------------------------------------------- a n N + 1 degree polynomial N + 1 ! •Notes • If fx = polynomial of degree M where MN , then N + 1 f x = 0 ex= 0 for all x Therefore gx will be an exact representation of fx p. 3.16 CE30125 - Lecture 3 N + 1 • Since in general is not known, if the interval xo xN is small and if f x does not change rapidly in the interval N + 1 xo + xN ex Lxf x where x = ------------------ . m m 2 N + 1 • f can be estimated by using Finite Difference (F.D.) formulae • Lx will significantly effect the distribution of the error • Lx is a minimum at the center of xo xN and a maximum near the edges • e.g. using 6 point interpolation Lx looks like: 012345 • Lx= 0 at all data points • Lx largest 0 x 1 4 x 5. Lx becomes very large outside of the interval. p. 3.17 CE30125 - Lecture 3 • As the size of the interpolating domain increases, so does the maximum error within the interval Dx= N – xo Lmax emax x0 xxN x0 xxN • As N increases from a small value, Lmax emax x0 xxN x0 xxN • However as NN CRIT Lmax for a given xo xN and thus emax x0 xxN x0 xxN • Therefore convergence as N does not necessarily occur!! N + 1 • Properties of f will also influence error as D and N vary p. 3.18 CE30125 - Lecture 3 Example • Estimate the error made in the previous example knowing that fx= lnx (usually we do not have this information). N + 1 ex Lxf xm xx– o xx– 1 xx– 2 xx– 3 31+ ex --------------------------------------------------------------------------- f x 31+ ! m 0.60– 0.40 0.60– 0.50 0.60– 0.70 0.60– 0.80 31+ e0.60 --------------------------------------------------------------------------------------------------------------------------------f 0.6 31+ ! 4 e0.60 = 0.000017 f 0.6 p.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages23 Page
-
File Size-