Vous êtes sur la page 1sur 15

CE 341/441 - Lecture 5 -Fall 2004

LECTURE 5 INTRODUCTION TO INTERPOLATION Interpolation function: a function that passes exactly through a set of data points. Interpolating functions to interpolate values in tables
x 0.0 0.5 1.0 1.5 2.0 2.5 sin(x) 0.000000 0.479426 0.841471 0.997495 0.909297 0.598472

In tables, the function is only specied at a limited number or discrete set of independent variable values (as opposed to a continuum function). We can use interpolation to nd functional values at other values of the independent variable, e.g. sin(0.63253)
p. 5.1

CE 341/441 - Lecture 5 -Fall 2004

In numerical methods, like tables, the values of the function are only specied at a discrete number of points! Using interpolation, we can describe or at least approximate the function at every point in space.

For numerical methods, we use interpolation to Interpolate values from computations Develop numerical integration schemes Develop numerical differentiation schemes Develop nite element methods

Interpolation is typically not used to obtain a functional description of measured data since errors in the data may lead to a poor representation. Curve tting to data is handled with a separate set of techniques

p. 5.2

CE 341/441 - Lecture 5 -Fall 2004

Linear Interpolation Linear interpolation is obtained by passing a straight line between 2 data points
y f(x1) f(x0) x0 x1 x g(x) f(x)

f ( x ) = the exact function for which values are known only at a discrete set of data points g ( x ) = the interpolated approximation to f ( x ) x 0 , x 1 = the data points (also referred to as interpolation points or nodes)

In tabular form:
xo x x1 f ( xo ) g( x) f ( x1 )
p. 5.3

CE 341/441 - Lecture 5 -Fall 2004

If g ( x ) is a linear function then


g ( x ) = Ax + B
(1)

where A and B are unknown coefcients To pass through points ( x o, f ( x o ) ) and ( x 1, f ( x 1 ) ) we must have:
g ( xo ) = f ( xo ) g ( x1 ) = f ( x1 )

Ax o + B = f ( x o ) Ax 1 + B = f ( x 1 )

(2) (3)

2 unknowns and 2 equations Using (2)

solve for A, B

B = f ( x o ) Ax o

Substituting into (3)


Ax 1 + f ( x o ) Ax o = f ( x 1 )

p. 5.4

CE 341/441 - Lecture 5 -Fall 2004

f ( x1 ) f ( xo ) A = --------------------------------x1 xo f ( xo ) x1 f ( x1 ) xo B = -------------------------------------------x1 xo

Substituting for A and B into equation (1)


( x1 x ) ( x xo ) - + f ( x 1 ) --------------------g ( x ) = f ( x o ) --------------------( x1 xo ) ( x1 xo )

This is the formula for linear interpolation

p. 5.5

CE 341/441 - Lecture 5 -Fall 2004

Example 1 Use values at x o and x 1 to get an interpolated value at x = 0.632 using linear interpolation
Table 1:

x x o = 0.5 0.632 x 1 = 1.0

f ( x ) = sin x f ( x o ) = 0.47942554 g ( 0.632 ) = ? f ( x 1 ) = 0.84147099

( 1.0 0.632 ) ( 0.632 0.5 ) g ( 0.632 ) = 0.479425 ------------------------------- + 0.84147099 ------------------------------( 1.0 0.5 ) ( 1.0 0.5 )

g ( 0.632 ) = 0.57500

p. 5.6

CE 341/441 - Lecture 5 -Fall 2004

Error for Linear Interpolating Functions Error is dened as:


e( x) f ( x) g( x)

e ( x ) represents the difference between the exact function f ( x ) and the interpolating or approximating function g ( x ) . We note that at the interpolating points x o and x 1
e ( xo ) = 0 e ( x1 ) = 0

This is because at the interpolating point we have by denition


g ( xo ) = f ( xo ) g ( x1 ) = f ( x1 )

p. 5.7

CE 341/441 - Lecture 5 -Fall 2004

Derivation of e(x)

f(x) f(x0) x0 f(x1)

f(x) g(x)

x1

e( x) f ( x) g( x)

Step 1 Expand f ( x ) in Taylor Series (T.S.) about x o


df f ( x ) = f ( x o ) + ( x x o ) ----dx ( x xo ) d 2 f - -------+ -------------------2 2! dx
2

where x o x
x=

(4)

x = xo

The third term is the actual remainder term and represents all other terms in the series since it is evaluated at x = !
p. 5.8

CE 341/441 - Lecture 5 -Fall 2004

Step 2
df Express ----dx
x = xo

in terms of f ( x o ) and f ( x 1 )

We can accomplish this by simply evaluating the T.S. in (4) at x = x 1 .


df f ( x 1 ) = f ( x o ) + ( x 1 x o ) ----dx

x = xo

( x1 xo ) d 2 f + ----------------------- -------2 2! dx

(5)
x=

df ----dx

x = xo

2 f ( x1 ) ( x1 xo ) f ( xo ) d f 1 - -------= -------------------- -------------------- ----------------------- -------------------( x1 xo ) d x2 ( x1 xo ) ( x1 xo ) 2!

(6)
x=

df ----dx

x = xo

( x1 xo ) d 2 f f ( x1 ) f ( xo ) - -------- -------------------- -------------------= -------------------2 2 ( x1 xo ) ( x1 xo ) dx

(7)
x=

We note that this is a discrete approximation to the rst derivative (a F.D. Formula)
p. 5.9

CE 341/441 - Lecture 5 -Fall 2004

Step 3 Substitute Equation 7 into T.S. form of f ( x ) , Equation (4). This gives us an expression for f ( x ) in terms of the discrete values f ( x o ) and f ( x 1 ) .
( x1 xo ) d 2 f f ( x1 ) f ( xo ) - -------f ( x ) = f ( x o ) + ( x x o ) -------------------- -------------------- -------------------2 2 ( x1 xo ) ( x1 xo ) dx

x=

( x xo ) d 2 f - -------+ -------------------2 2 dx

(8)
x=

( x xo ) ( x xo ) ( x xo ) ( x1 + xo ) ( x xo ) d 2 f - f ( x 1 ) -------------------- f ( x o ) + ------------------------------------------f ( x ) = f ( x o ) + -------------------- -------- + -------------------2 ( x1 xo ) ( x1 xo ) 2 2 dx

(9)
x=

( x xo ) d 2 f f ( xo ) f ( x1 ) - -------- + ( x x o ) -------------------- + ( x 1 + x o + x x o ) -----------------f ( x ) = ( x 1 x o x + x o ) -------------------2 d x2 ( x1 xo ) ( x1 xo )

(10)
x=

( x xo ) ( x x1 ) d 2 f x1 x x xo - + f ( x 1 ) ---------------- + --------------------------------------- -------f ( x ) = f ( x o ) ---------------2 x1 xo x1 xo 2 dx


p. 5.10

(11)
x=

CE 341/441 - Lecture 5 -Fall 2004

The rst part of Equation (11) is simply the linear interpolation formula. The second part is in fact the error. Thus:
e( x) f ( x) g( x)

( x xo ) ( x x1 ) d 2 f x1 x x xo - + f ( x 1 ) --------------- + ------------------------------------- -------e ( x ) f ( x o ) --------------2 x1 xo x1 xo 2 dx x1 x x xo - f ( x 1 ) -------------- f ( x o ) --------------x1 xo x1 xo

x=

( x xo ) ( x x1 ) d 2 f - -------e ( x ) = --------------------------------------2 2 dx

xo x1
x=

If we assume that the interval [ x o, x 1 ] is small, then the second derivative wont change dramatically in the interval!
d f -------2 dx
2

d f -------2 dx x=

x = xo

d f -------2 dx

x = x1

d f -------2 dx

where
x = xm

xo + x1 x m ---------------2

p. 5.11

CE 341/441 - Lecture 5 -Fall 2004

Thus we typically evaluate the derivative term in the error expression using the midpoint in the interval
1 d f - ( x x o ) ( x x 1 ) -------e ( x ) -2 2 dx
2

x = xm

Another problem is that we typically dont know the second derivative at the midpoint of the interval, x m However using nite differencing formulae we can approximate this derivative knowing the functional values at the interpolating points Maximum error occurs at the midpoint for linear interpolation (where ( x x o ) ( x x 1 ) is the largest)
1 d f - ( x m x o ) ( x m x 1 ) -------max e ( x ) x < x < x -2 0 1 2 dx
2

x = xm

However
h x1 xo

and
h h -- = x m x o and -- = x1 xm 2 2
p. 5.12

CE 341/441 - Lecture 5 -Fall 2004

Thus
max e ( x )
x0 < x < x1

h d f = ----- -------8 d x2

2 2

xm

Notes on Error for linear interpolation The error expression has a polynomial and a derivative portion. Maximum error occurs approximately at the midpoint between x o and x 1 Error increases as the interval h increases
) (2) Error increases as f ( 2( x ) increases. Again note that f ( x ) can be approximated with nite difference (F.D.) formulae if at least 3 surrounding functional values are available. (We will discuss F.D. formulae later.)

p. 5.13

CE 341/441 - Lecture 5 -Fall 2004

Example 2 Compute an error estimate for the problem in Example 1. Recall we found that
g ( 0.632 ) = 0.57500

Error is estimated as:


1 d f - ( x x o ) ( x x 1 ) -------e ( x ) -2 2 dx
2

x = xm

Since x = 0.750 is the midpoint at the interval [ 0.5, 1.0 ] , we have


d f 1 - ( 0.632 0.5 ) ( 0.632 1.0 ) -------e ( 0.632 ) -2 2 dx

x = 0.750

d f e ( 0.632 ) 0.024288 -------2 dx

x = 0.75

p. 5.14

CE 341/441 - Lecture 5 -Fall 2004

Since we have not yet extensively discussed approximating derivatives using discrete
f -------values, we will compute d 2 dx d f -------2 dx
2 2

using analytical methods:


x = 0.75

= sin ( 0.750 ) = 0.68164


x = 0.75 2

f ------- Substituting in the value for d 2 dx

, we obtain an estimate for the error:


x = 0.75

e ( 0.632 ) ( 0.024288 ) ( 0.68164 ) = 0.016555

Computing the actual error (the actual solution - the estimated error):
E ( x ) = sin ( x ) g ( x ) E ( 0.632 ) = sin ( 0.632 ) 0.57500 = 0.01576

The estimated error, e ( x ) is a good approximation of the actual error E ( x ) !


p. 5.15

Vous aimerez peut-être aussi