You are on page 1of 23

CE 341/441 - Lecture 6 - Fall 2004

LECTURE 6
LAGRANGE INTERPOLATION
th
Fit N + 1 points with an N degree polynomial

g(x)

f2

f0
x0

f1

f(x)
f3

x1 x2 x3

f4
fN
x4 ...

xN

f ( x ) = exact function of which only N + 1 discrete values are known and used to establish an interpolating or approximating function g ( x )
g ( x ) = approximating or interpolating function. This function will pass through all
specified N + 1 interpolation points (also referred to as data points or nodes).

p. 6.1

CE 341/441 - Lecture 6 - Fall 2004

The interpolation points or nodes are given as:


xo

f ( xo ) f o

x1

f ( x1 ) f 1

x2

f ( x2 ) f 2

xN

f ( xN ) f N

There exists only one N th degree polynomial that passes through a given set of N + 1
points. Its form is (expressed as a power series):
2

g ( x ) = ao + a1 x + a2 x + a3 x + + a N x

where a i = unknown coefficients, i = 0, N ( N + 1 coefficients).


No matter how we derive the N th degree polynomial,
Fitting power series
Lagrange interpolating functions
Newton forward or backward interpolation
The resulting polynomial will always be the same!
p. 6.2

CE 341/441 - Lecture 6 - Fall 2004

Power Series Fitting to Define Lagrange Interpolation


g ( x ) must match f ( x ) at the selected data points

g ( xo ) = f o

ao + a1 xo + a2 xo + + a N xo = f o

g ( x1 ) = f 1

ao + a1 x1 + a2 x1 + + a N x1 = f 1

g( xN ) = f N

ao + a1 x N + a2 x N + + a N x N = f N

Solve set of simultaneous equations


2

1 xo xo xo

ao

1 x1 x1 x1

a1

:
aN

1 xN xN xN

fo
=

f1
:
fN

It is relatively computationally costly to solve the coefficients of the interpolating function g ( x ) (i.e. you need to program a solution to these equations).
p. 6.3

CE 341/441 - Lecture 6 - Fall 2004

Lagrange Interpolation Using Basis Functions


We note that in general g ( x i ) = f i
Let
N

g( x) =

f i V i( x)

i=0

where V i ( x ) = polynomial of degree N associated with each node i such that


0 i j
V i( x j)
1 i = j

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


g ( x3 ) = f o V o ( x3 ) + f 1 V 1 ( x3 ) + f 2 V 2 ( x3 ) + f 3 V 3 ( x3 ) + f 4 V 4 ( x3 )

Using the definition for V i ( x j ) : V 0 ( x 3 ) = 0 ; V 1 ( x 3 ) = 0 ; V 2 ( x 3 ) = 0 ; V 3 ( x 3 ) = 1 ;


V 4 ( x 3 ) = 0 ,we have:
g ( x3 ) = f 3
p. 6.4

CE 341/441 - Lecture 6 - Fall 2004

How do we construct V i ( x ) ?
Degree N
Roots at x o, x 1, x 2, x i 1, x i + 1, , x N (at all nodes except x i )
V i ( xi ) = 1
Let W i ( x ) = ( x x o ) ( x x 1 ) ( x x 2 ) ( x x i 1 ) ( x x i + 1 ) ( x x N )
The function W i is such that we do have the required roots, i.e. it equals zero at
nodes x o, x 1, x 2, ... , x N except at node x i
Degree of W i ( x ) is N
However W i ( x ) in the form presented will not equal to unity at x i
We normalize W i ( x ) and define the Lagrange basis functions V i ( x )
( x x o ) ( x x 1 ) ( x x 2 ) ( x x i 1 ) ( x x i + 1 ) ( x x N )
V i ( x ) = ----------------------------------------------------------------------------------------------------------------------------------------------------------( x i x o ) ( x i x 1 ) ( x i x 2 ) ( x i x i 1 ) ( x i x i + 1 ) ( x i x N )

p. 6.5

CE 341/441 - Lecture 6 - Fall 2004

Now we have V i ( x ) such that V i ( x i ) equals:


( x i x o ) ( x i x 1 ) ( x i x 2 ) ( x i x i 1 ) ( 1 ) ( x i x i + 1 ) ( x i x N )
V i ( x i ) = ------------------------------------------------------------------------------------------------------------------------------------------------------------( x i x o ) ( x i x 1 ) ( x i x 2 ) ( x i x i 1 ) ( x i x i + 1 ) ( x i x N )

V i ( xi ) = 1

We also satisfy V i ( x j ) = 0 for i j


e.g.

( x2 xo ) ( 1 ) ( x2 x2 ) ( x2 x3 ) ( x2 x N )
= 0
V 1 ( x 2 ) = ---------------------------------------------------------------------------------------------------------( x 1 x o ) ( 1 ) ( x 1 x 2 ) ( x 1 x 3 ) ( x 1 x N )

The general form of the interpolating function g ( x ) with the specified form of V i ( x ) is:
N

g( x) =

f iV i( x)

i=0

The sum of polynomials of degree N is also polynomial of degree N


g ( x ) is equivalent to fitting the power series and computing coefficients a o, , a N .
p. 6.6

CE 341/441 - Lecture 6 - Fall 2004

Lagrange Linear Interpolation Using Basis Functions


Linear Lagrange ( N = 1 ) is the simplest form of Lagrange Interpolation
1

g( x) =

f iV i( x)

i=0

g( x) = f oV o( x) + f 1V 1( x)

where
( x1 x )
( x x1 )
V o ( x ) = --------------------- = --------------------( x1 xo )
( xo x1 )

1.0

and

( x xo )
V 1 ( x ) = -------------------( x1 xo )

V1(x)

V0 (x)

(x)
x0

x1

p. 6.7

CE 341/441 - Lecture 6 - Fall 2004

Example
Given the following data:
xo = 2

f o = 1.5

x1 = 5

f 1 = 4.0

Find the linear interpolating function g ( x )

Lagrange basis functions are:


5x
V o ( x ) = ----------3

and

x2
V 1 ( x ) = ----------3

Interpolating function g(x) is:


g ( x ) = 1.5V o ( x ) + 4.0V 1 ( x )

p. 6.8

CE 341/441 - Lecture 6 - Fall 2004

4
1.5 V0 (x)

x
x0 = 2

x1 = 5

4
4.0 V1(x)

2
x0 = 2

x1 = 5

g(x) = 1.5 V0(x) + 4.0V1(x)

x0 = 2

x1 = 5

p. 6.9

CE 341/441 - Lecture 6 - Fall 2004

Lagrange Quadratic Interpolation Using Basis Functions


For quadratic Lagrange interpolation, N=2
2

g( x) =

f i V i( x)

i=0

g( x) = f oV o( x) + f 1V 1( x) + f 2V 2( x)

where
( x x1 ) ( x x2 )
V o ( x ) = -----------------------------------------( xo x1 ) ( xo x2 )
( x xo ) ( x x2 )
V 1 ( x ) = -----------------------------------------( x1 xo ) ( x1 x2 )
( x xo ) ( x x1 )
V 2 ( x ) = -----------------------------------------( x2 xo ) ( x2 x1 )

p. 6.10

CE 341/441 - Lecture 6 - Fall 2004

V0 (x)

V1(x)

V2(x)

1.0

x
x0

x1

x2

Note that the location of the roots of V 0 ( x ) , V 1 ( x ) and V 2 ( x ) are defined such that the
basic premise of interpolation is satisfied, namely that g ( x i ) = f i . Thus:
g ( xo ) = V o ( xo ) f o + V 1 ( xo ) f 1 + V 2 ( xo ) f 2 = f 0
g ( x1 ) = V o ( x1 ) f o + V 1 ( x1 ) f 1 + V 2 ( x1 ) f 2 = f 1
g ( x2 ) = V o ( x2 ) f o + V 1 ( x2 ) f 1 + V 2 ( x2 ) f 2 = f 2
p. 6.11

CE 341/441 - Lecture 6 - Fall 2004

Example
Given the following data:
xo = 3

fo = 1

x1 = 4

f1 = 2

x2 = 5

f2 = 4

Find the quadratic interpolating function g ( x )


Lagrange basis functions are
( x 4)( x 5)
V o ( x ) = ---------------------------------(3 4)(3 5)
( x 3)( x 5)
V 1 ( x ) = ---------------------------------(4 3)(4 5)
( x 3)( x 4)
V 2 ( x ) = ---------------------------------(5 3)(5 4)

Interpolating function g(x) is:


g ( x ) = 1.0V o ( x ) + 2.0V 1 ( x ) + 4.0V 2 ( x )
p. 6.12

CE 341/441 - Lecture 6 - Fall 2004

1.0 V0 (x)

1.0

x0 = 3

x1 = 4

x2 = 5

2.0 V1(x)

2.0

x0 = 3 x1 = 4 x2 = 5

4.0 V2(x)

4.0

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. 6.13

CE 341/441 - Lecture 6 - Fall 2004

Lagrange Cubic Interpolation Using Basis Functions


For Cubic Lagrange interpolation, N=3
Example
Consider the following table of functional values (generated with f ( x ) = ln x )
i

xi

fi

0.40

-0.916291

0.50

-0.693147

0.70

-0.356675

0.80

-0.223144

Find g ( 0.60 ) as:


( x x1 ) ( x x2 ) ( x x3 )
( x xo ) ( x x2 ) ( x x3 )
g ( x ) = f o ----------------------------------------------------------------- + f 1 ----------------------------------------------------------------( xo x1 ) ( xo x2 ) ( xo x3 )
( x1 xo ) ( x1 x2 ) ( x1 x3 )
( x xo ) ( x x1 ) ( x x3 )
( x xo ) ( x x1 ) ( x x2 )
+ f 2 ----------------------------------------------------------------- + f 3 ----------------------------------------------------------------( x2 xo ) ( x2 x1 ) ( x2 x3 )
( x3 xo ) ( x3 x1 ) ( x3 x2 )

p. 6.14

CE 341/441 - Lecture 6 - Fall 2004

( 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. 6.15

CE 341/441 - Lecture 6 - Fall 2004

Errors Associated with Lagrange Interpolation


Using Taylor series analysis, the error can be shown to be given by:
e( x) = f ( x) g( x)
e( x) = L( x) f

( N + 1)

()

xo x N

where
f

N+1

() = N + 1

th

derivative of f w.r.t. x evaluated at

( x x o ) ( x x 1 ) ( x x N )
th
L ( x ) = ---------------------------------------------------------------- = an N + 1 degree polynomial
( N + 1 )!

Notes
If f ( x ) = polynomial of degree M where M N , then
f

(N + 1)

( x) = 0

e ( x ) = 0 for all x

Therefore g ( x ) will be an exact representation of f ( x )

p. 6.16

CE 341/441 - Lecture 6 - Fall 2004

Since in general is not known, if the interval [ x o, x N ] is small and if f ( N + 1 ) ( x )


does not change rapidly in the interval
e( x) L( x) f

( N + 1)

( x m ) where x m

xo + x N
= ------------------- .
2

f ( N + 1 ) can be estimated by using Finite Difference (F.D.) formulae


L ( x ) will significantly effect the distribution of the error
L ( x ) is a minimum at the center of [ x o, x N ] and a maximum near the edges
e.g. using 6 point interpolation L ( x ) looks like:

1 2

3 4

L ( x ) = 0 at all data points


L ( x ) largest 0 x 1 4 x 5 . L ( x ) becomes very large outside of the interval.
p. 6.17

CE 341/441 - Lecture 6 - Fall 2004

As the size of the interpolating domain increases, so does the maximum error within
the interval
D = x N x o L max

x0 x x N

As N increases from a small value, L max

However as N > N CRIT

L max

x0 x x N

Therefore convergence as N

x0 x x N

e max

x0 x x N

e max

x0 x x N

for a given [ x o, x N ] and thus e max

does not necessarily occur!!

Properties of f ( N + 1 ) ( ) will also influence error as D and N vary

p. 6.18

x0 x x N

CE 341/441 - Lecture 6 - Fall 2004

Example
Estimate the error made in the previous example knowing that f ( x ) = ln ( x ) (usually we
do not have this information).
e( x) L( x) f

(N + 1)

( xm )

( x xo ) ( x x1 ) ( x x2 ) ( x x3 )
e ( x ) ----------------------------------------------------------------------------( 3 + 1 )!

(3 + 1)

( xm )

( 0.60 0.40 ) ( 0.60 0.50 ) ( 0.60 0.70 ) ( 0.60 0.80 ) ( 3 + 1 )


e ( 0.60 ) -------------------------------------------------------------------------------------------------------------------------------- f
( 0.6 )
( 3 + 1 )!

e ( 0.60 ) = 0.000017

(4)

( 0.6 )

p. 6.19

CE 341/441 - Lecture 6 - Fall 2004

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

(1)

( x) = x

(2)

( x) = x

(3)

( x ) = 2x

(4)

( x ) = 6x

(4)

( 0.6 ) = 46.29

Therefore
e ( 0.60 ) = 0.00079

Exact error is computed as:


E ( x ) = ln ( 0.60 ) g ( 0.60 ) = 0.00085

Therefore error estimate is excellent


(N + 1)
( x m ) using a Finite Difference (F.D.)
Typically we would also have to estimate f

approximation (a discrete differentiation formula).


p. 6.20

CE 341/441 - Lecture 6 - Fall 2004

SUMMARY OF LECTURES 5 AND 6


Linear interpolation passes a straight line through 2 data points.
Power series N + 1 data points
solving a matrix

th

degree polynomial

find coefficients by

th
Lagrange Interpolation passes an N degree polynomial through N + 1 data points
Use specialized nodal functions to make finding g ( x ) easier.

g( x) =

f iV i( x)

i=0

where
g ( x ) = the interpolating function approximating f(x)

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


V i ( x ) = the Lagrange basis function

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 inbetween.
p. 6.21

CE 341/441 - Lecture 6 - Fall 2004

For example when N = 2 3 data points

V0

V1

V2

g( x) = f oV o( x) + f 1V 1( x) + f 2V 2( x)

f0
g(x)
f1

p. 6.22

f2

CE 341/441 - Lecture 6 - Fall 2004

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


Error estimates can be derived but depend on knowing f ( N + 1 ) ( x m ) (or at some point in
the interval).
e( x) = L( x) f

( N + 1)

()

xo x N

where
f

N+1

() = N + 1

th

derivative of f w.r.t. x evaluated at

( x x o ) ( x x 1 ) ( x x N )
th
L ( x ) = ---------------------------------------------------------------- = an N + 1 degree polynomial
( N + 1 )!

p. 6.23

You might also like