<<

CE30125 - Lecture 3

LECTURE 3

LAGRANGE

th • Fit N + 1 points with an N degree

g(x) f 2 f(x) f f 3 f4 1 f f0 N

x0 x1 x2 x3 x4 ... xN

•fx = exact 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 fxo  fo

x1 fx1  f1

x2 fx2  f2 : xN fxN  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 gxo = fo  ao ++++a1xo a2xo  aNxo = fo

2 N gx1 = f1  ao ++a1x1 a2x1 ++ aNx1 = f1 : : 2 N gxN = 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 gxi = fi •Let N

gx=  fi Vix i = 0

where Vix = polynomial of degree N associated with each node i such that

 0 i  j Vixj   1 i = j

• For example if we have 5 interpolation points (or nodes)

gx3 = foVox3 ++++f1V1x3 f2V2x3 f3V3x3 f4V4x3

Using the definition for Vixj : V0x3 = 0 ; V1x3 = 0 ; V2x3 = 0 ; V3x3 = 1 ;

V4x3 = 0 ,we have:

gx3 = f3

p. 3.4 CE30125 - Lecture 3

• How do we construct Vix ?

• Degree N

• Roots at xox1 x2 xi – 1 xi + 1  xN (at all nodes except xi )

• Vixi = 1

•Let Wix = 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

xox1 x2 ... , xN except at node xi

• Degree of Wix is N

• However Wix in the form presented will not equal to unity at xi

• We normalize Wix and define the Lagrange basis functions Vix

xx– o xx– 1 xx– 2 xx– i – 1 xx– i + 1 xx– N Vix = ------xi – xo xi – x1 xi – x2 xi – xi – 1 xi – xi + 1 xi – xN

p. 3.5 CE30125 - Lecture 3

• Now we have Vix such that Vixi equals:

xi – xo xi – x1 xi – x2 xi – xi – 1 1 xi – xi + 1 xi – xN Vixi = ------ xi – xo xi – x1 xi – x2 xi – xi – 1 xi – xi + 1 xi – xN

Vixi = 1

• We also satisfy Vixj = 0 for ij

x2 – xo 1 x2 – x2 x2 – x3 x2 – xN e.g. V1x2 ==------0 x1 – xo 1 x1 – x2 x1 – x3 x1 – xN

• The general form of the interpolating function gx with the specified form of Vix is:

N

gx=  fiVix i = 0 • The sum of 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 Using Basis Functions

• Linear Lagrange N = 1 is the simplest form of Lagrange Interpolation 1

gx=  fiVix i = 0 

gx= foVox + f1V1x where

xx– 1 x1 – x xx– o Vox ==------and V1x = ------xo – x1 x1 – xo x1 – xo

V (x) V1(x) 1.0 0

(x) x x0 1

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.5Vox + 4.0V1x

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 Vix i = 0

gx= foVox ++f1V1x f2V2x

where

xx– 1 xx– 2 Vox = ------xo – x1 xo – x2

xx– o xx– 2 V1x = ------x1 – xo x1 – x2

xx– o xx– 1 V2x = ------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 V0x , V1x and V2x are defined such that the

basic premise of interpolation is satisfied, namely that gxi = fi . Thus:

gxo ==Voxo fo ++V1xo f1 V2xo f2 f0

gx1 ==Vox1 fo ++V1x1 f1 V2x1 f2 f1

gx2 ==Vox2 fo ++V1x2 f1 V2x2 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.0Vox ++2.0V1x 4.0V2x

p. 3.12 CE30125 - Lecture 3

1.0 V (x) 1.0 0 x x 0 = 3 x 2 = 5 x1 = 4

2.0 2.0 V1(x) x x0 = 3 x1 = 4 x 2 = 5

4.0 4.0 V 2(x)

x x0 = 3 x1 = 4 x 2 = 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 g0.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 g0.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

g0.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= Lxf  xo  xN where

N + 1 th f  = N + 1 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 Lxf 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= lnx (usually we do not have this information).

N + 1 ex Lxf 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+ e0.60  ------f 0.6 31+ !

4 e0.60 = 0.000017 f 0.6

p. 3.19 CE30125 - Lecture 3

• We estimate the fourth derivative of f(x) using the analytical function itself

fx= lnx 

1 –1 f x = x 

2 –2 f x = –x 

3 –3 f x = 2x 

4 –4 f x = –6x 

4 f 0.6 = –46.29 • Therefore

e0.60 = –0.00079 • Exact error is computed as:

Ex==ln0.60 –g0.60 – 0.00085

Therefore error estimate is excellent

N + 1 • Typically we would also have to estimate f xm using a Finite Difference (F.D.) approximation (a discrete differentiation formula).

p. 3.20 CE30125 - Lecture 3

SUMMARY OF LECTURES 2 AND 3

• Linear interpolation passes a straight line through 2 data points.

th • Power series  N + 1 data points  N degree polynomial  find coefficients by solving a matrix

th • Lagrange Interpolation passes an N degree polynomial through N + 1 data points  Use specialized nodal functions to make finding gx easier.

N

gx=  fiVix i = 0 where

gx = the interpolating function approximating f(x)

fi = the value of the function at the data (or interpolation) point i

Vix = the Lagrange • Each Lagrange polynomial or basis function is set up such that it equals unity at the data point with which it is associated, zero at all other data points and nonzero in- between.

p. 3.21 CE30125 - Lecture 3

• For example when N =2  3 data points

V V1 0 V2

0 12

gx= foVox ++f1V1x f2V2x

f0 g(x) f2

f1

p. 3.22 CE30125 - Lecture 3

• Linear interpolation is the same as Lagrange Interpolation with N = 1

N + 1 • Error estimates can be derived but depend on knowing f xm (or at some point in the interval).

N + 1 ex= Lxf  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 !

p. 3.23