NUMERICAL METHODS IN ENGINEERING ENGR 391

Post on 17-Apr-2022

11 views 1 download

transcript

The Islamic University of Gaza

Faculty of Engineering

Civil Engineering Department

Numerical Analysis

ECIV 3306

Chapter 18

Interpolation

Associate Prof. Mazen Abualtayef Civil Engineering Department, The Islamic University of Gaza

Introduction

Estimation of intermediate values between precise data points. The most common method is polynomial interpolation:

Polynomial interpolation is used when the point determined are very precise. The curve representing the behavior has to pass through every point.

There is one and only one nth-order polynomial that fits n+1 points

n

nxaxaxaaxf 2

210)(

Introduction

First order (linear) 3rd order (cubic) 2nd order (quadratic)

n = 2 n = 3 n = 4

Introduction

There are a variety of mathematical formats in

which this polynomial can be expressed:

The Newton polynomial (Section 18.1)

The Lagrange polynomial (Section 18.2)

Lagrange Interpolating Polynomials

• The general form for n+1 data points is:

n

ijj ji

j

i

n

i

iin

xx

xxxL

xfxLxf

0

0

)(

)()()(

designates the “product of”

Lagrange Interpolating Polynomials

)()()( 1

01

00

10

11 xf

xx

xxxf

xx

xxxf

• Linear version (n = 1):

Used for 2 points of data: (xo,f(xo)) and (x1,f(x1)),

)(xLo )(1 xL

n

ijj ji

j

i

n

i

iin

xx

xxxL

xfxLxf

0

0

)(

)()()(

Lagrange Interpolating Polynomials

1,)(1 jxL

)(

)(

)()(

2

1202

10

1

2101

20

0

2010

212

xfxxxx

xxxx

xfxxxx

xxxx

xfxxxx

xxxxxf

2,)(2 jxL

• Second order version (n = 2):

0,)( jxLo

n

ijj ji

j

i

n

i

iin

xx

xxxL

xfxLxf

0

0

)(

)()()(

Lagrange Interpolating Polynomials Example 18.6

Use a Lagrange interpolating polynomial of the first and second order to evaluate ln(2) on the basis of the data:

10 x 0)1ln()( 0 xf

41 x

62 x

386294.1)4ln()( 1 xf

791760.1)6ln()( 2 xf

Lagrange Interpolating Polynomials – Example 18.6 (cont’d)

• First order polynomial:

)()()( 1

01

0

0

10

1

1 xfxx

xxxf

xx

xxxf

4620981.0386294.114

120

41

42)2(1

f

Lagrange Interpolating Polynomials – Example (cont’d)

• Second order polynomial:

60

6x

40

4x

xx

xx

xx

xxxL

2o

2

1o

1o

)(

64

6x

04

0x

xx

xx

xx

xxxL

21

2

o1

o1

)(

46

4x

06

0x

xx

xx

xx

xxxL

12

1

o2

o2

)(

Lagrange Interpolating Polynomials – Example (cont’d)

5658444.0 791760.1)46)(16(

)42)(12(

386294.1)64)(14(

)62)(12(

0)61)(41(

)62)(42()2(2

f

n

0i

iin xfxLxf )()()( )()( ijxx

xxxL

n

0j ji

j

i

Lagrange Interpolating Polynomials – Example (cont’d)

Pseudocode – Lagrange interpolation

Coefficients of an Interpolating Polynomial

• Although “Lagrange” polynomials are well suited for determining intermediate values between points, they do not provide a polynomial in conventional form:

• Since n+1 data points are required to determine n+1 coefficients, simultaneous linear systems of equations can be used to calculate “a”s.

n

xxaxaxaaxf 2

210)(

Coefficients of an Interpolating Polynomial (cont’d)

n

nnnnn

n

n

n

n

xaxaxaaxf

xaxaxaaxf

xaxaxaaxf

2

210

1

2

121101

0

2

020100

)(

)(

)(

Where “x”s are the knowns and “a”s are the

unknowns.

16

Interpolantion

Polynomials are the most common choice of interpolation because they are easy to:

Evaluate

Differentiate, and

Integrate.

Possible divergence of an extrapolated production

18

Why Spline Interpolation?

Apply lower-order polynomials to subsets of data points. Spline

provides a superior approximation of the behavior of functions that

have local, abrupt changes.

19

Why Splines ?

2251

1)(

xxf

Table : Six equidistantly spaced points in [-1, 1]

Figure : 5th order polynomial vs. exact function

x 2251

1

xy

-1.0 0.038461

-0.6 0.1

-0.2 0.5

0.2 0.5

0.6 0.1

1.0 0.038461

20

Why Splines ?

Figure : Higher order polynomial interpolation is a bad idea

Original

Function

17th

Order

Polynomial

9th

Order

Polynomial

5th

Order

Polynomial

Spline Interpolation

• Polynomials are the most common choice of interpolants.

• There are cases where polynomials can lead to erroneous results because of round off error and overshoot.

• Alternative approach is to apply lower-order polynomials to subsets of data points. Such connecting polynomials are called spline functions.

Spline Interpolation

The concept of spline is using a thin, flexible strip (called a spline) to draw smooth curves through a set of points….natural spline (cubic)

Linear Spline

The first order splines for a group of ordered data points can be defined as a set of linear functions:

ii

iii

xx

xfxfm

1

1 )()(

)()()( 000 xxmxfxf 10 xxx

)()()( 111 xxmxfxf 21 xxx

)()()( 111 nnn xxmxfxf nn xxx 1

Linear spline - Example

Fit the following data with first order splines. Evaluate the function at x = 5.

x f(x)

3.0 2.5

4.5 1.0

7.0 2.5

9.0 0.5

6.05.47

15.2

m

3.1

5.06.00.1

)5.45()5.4()5(

mff

Linear Spline

• The main disadvantage of linear spline is that they are not smooth. The data points where 2 splines meets called (a knot), the changes abruptly.

• The first derivative of the function is discontinuous at these points.

• Using higher order polynomial splines ensure smoothness at the knots by equating derivatives at these points.

Quadric Splines

iiii cxbxaxf 2)(

• Objective: to derive a second order polynomial for each

interval between data points.

• Terms: Interior knots and end points

For n+1 data points:

• i = (0, 1, 2, …n), • n intervals,

• 3n unknown

constants (a’s, b’s and c’s)

Quadric Splines

• The function values of adjacent polynomial must be equal at the interior knots 2(n-1).

• The first and last functions must pass through the end points (2).

nixfcxbxa

nixfcxbxa

iiiiiii

iiiiiii

,...,4,3,2)(

,...,4,3,2)(

11

2

1

1111

2

11

)(

)(

2

0101

2

01

nnnnnn xfcxbxa

xfcxbxa

Quadric Splines

• The first derivatives at the interior knots must be equal (n-1).

• Assume that the second derivate is zero at

the first point (1)

(The first two points will be connected by a straight line)

iiiiii

iii

bxabxa

bxaxf

1111

'

22

2)(

01 a

Quadric Splines - Example

Fit the following data with quadratic splines. Estimate the value at x = 5.

Solutions:

There are 3 intervals (n=3), 9 unknowns.

x 3.0 4.5 7.0 9.0

f(x) 2.5 1.0 2.5 0.5

Quadric Splines - Example

1. Equal interior points:

For first interior point (4.5, 1.0)

The 1st equation:

The 2nd equation:

)( 1221221 xfcbxax

0.15.425.20 111 cba

)( 1111121 xfcbxax

)5.4(5.4)5.4( 1112 fcba

0.15.425.20 222 cba)5.4(5.4)5.4( 2222 fcba

Quadric Splines - Example

For second interior point (7.0, 2.5)

The 3rd equation:

The 4th equation:

5.2749 222 cba

5.2749 333 cba

)( 22222

2

2 xfcbxax

)7(7)7( 222

2 fcba

)( 23323

2

2 xfcbxax

)7(7)7( 333

2 fcba

Quadric Splines - Example

First and last functions pass the end points

For the start point (3.0, 2.5)

For the end point (9, 0.5)

5.239 111 cba

5.0981 333 cba

)( 01101

2

0 xfcbxax

)( 33333

2

3 xfcbxax

Quadric Splines - Example

Equal derivatives at the interior knots.

For first interior point (4.5, 1.0)

For second interior point (7.0, 2.5)

Second derivative at the first point is 0

0)( 10'' axf

2211 99 baba 221111 22 baxbax

3322 1414 baba 333222 22 baxbax

Quadratic Splines - Example

5.51

1

5.2

1

13

15.4 1

1

1

c

b

c

b

46.18

76.6

64.0

1

5.2

1

019

1749

15.425.20

2

2

2

2

2

2

c

b

a

c

b

a

Eq.(1) & Eq.(5)

Eq.(2) , Eq.(3) & Eq. (7)

391c

6024b

601a

22

50

52

c

b

a

0114

1981

1749

3

3

3

3

3

3

.

.

.

.

.

.Eq.(4) , Eq.(6) & Eq. (8)

Quadratic Splines - Example

0

0

5.0

5.2

5.2

5.2

1

1

0114011400

00001901

198100000

00000013

174900000

000174900

00015.425.2000

00000015.4

3

3

3

2

2

2

1

1

c

b

a

c

b

a

c

b

Quadric Splines - Example

Solving these 8 equations with 8 unknowns

3.91,6.24,6.1

46.18,76.6,64.0

5.5,1,0

333

222

111

cba

cba

cba

,5.5)(1 xxf 5.40.3 x

,46.1876.664.0)( 2

2 xxxf 0.75.4 x

,3.916.246.1)( 23 xxxf 0.90.7 x

x 3.0 4.5 7.0 9.0

f(x) 2.5 1.0 2.5 0.5

4 6 8

Cubic Splines

iiiii dxcxbxaxf 23)(

Objective: to derive a third order polynomial for

each interval between data points.

Terms: Interior knots and end points

For n+1 data points:

• i = (0, 1, 2, …n),

• n intervals,

• 4n unknown constants (a’s, b’s ,c’s and d’s)

Cubic Splines

• The function values must be equal at the interior knots (2n-2).

• The first and last functions must pass through the end points (2).

• The first derivatives at the interior knots must be equal (n-1).

• The second derivatives at the interior knots must be equal (n-1).

• The second derivatives at the end knots are zero (2), (the 2nd derivative function becomes a straight line at the end points)

Alternative technique to get Cubic Splines

• The second derivative within each interval [xi-1, xi ] is a

straight line. (the 2nd derivatives can be represented by first

order Lagrange interpolating polynomials.

1

1''

1

1

'''')()()(

ii

iii

ii

iiii

xx

xxxf

xx

xxxfxf

A straight line

connecting the first

knot f’’(xi-1) and the

second knot f’’(xi)

The second derivative at any point x within the interval

Cubic Splines

• The last equation can be integrated twice

2 unknown constants of integration can be evaluated by applying the boundary conditions:

1. f(x) = f (xi-1) at xi-1

2. f(x) = f (xi) at xi

1

1

''

1

11

''

1

1

3

1

1

''3

1

1

''

6

)()(

6

)()(

6

)(

6

)()(

iiiii

ii

ii

iiiii

ii

ii

i

ii

iii

ii

iii

xxxxxf

xx

xf

xxxxxf

xx

xf

xxxx

xfxx

xx

xfxf

)('' ixf

Unknowns:

)('' 1ixf

i = 0, 1,…, n

Cubic Splines

)()(6

)()(6

)()(

)()(2)()(

1

1

1

1

1

''

1

''

111

''

1

ii

ii

ii

ii

iii

iiiiii

xfxfxx

xfxfxx

xfxx

xfxxxfxx

• For each interior point xi (n-1):

This equation result with n-1 unknown second derivatives where, for boundary points:

f˝(xo) = f˝(xn) = 0

)()(''

1 iii xfxfi

Cubic Splines – Example 18.10

Fit the following data with cubic splines

Use the results to estimate the value at x=5.

Solution:

Natural Spline:

x 3.0 4.5 7.0 9.0

f(x) 2.5 1.0 2.5 0.5

0)9()(,0)3()( ''

3

''''

0

'' fxffxf

Cubic Splines - Example

For 1st interior point (x1 = 4.5)

-

-

-

Apply the following equation:

)()(6

)()(6

)()()()(2)()(

1

1

1

1

1

''

1

''

111

''

1

ii

ii

ii

ii

iiiiiiiii

xfxfxx

xfxfxx

xfxxxfxxxfxx

x 3.0 4.5 7.0 9.0

f(x) 2.5 1.0 2.5 0.5

5.10.35.4011 xxxx ii

5.25.47121 xxxx ii

40.370211 xxxx ii

Cubic Splines - Example

)15.2(5.1

6)15.2(

5.2

6)7(5.2)5.4(42)3(5.1 '''''' fff

0)3('' f

)1.(..............6.9)7(5.2)5.4(8 '''' eqff

x 3.0 4.5 7.0 9.0

f(x) 2.5 1.0 2.5 0.5

Since

For 2nd interior point (x2 = 7 )

5.25.47121 xxxx ii

5.45.491311 xxxx ii

279231 xxxx ii

Cubic Splines - Example

Apply the following equation:

)()(6

)()(6

)()()()(2)()(

1

1

1

1

1

''

1

''

111

''

1

ii

ii

ii

ii

iiiiiiiii

xfxfxx

xfxfxx

xfxxxfxxxfxx

)5.21(5.2

6)5.25.0(

2

6)9(2)7(5.42)5.4(5.2 '''''' fff

Since 0)9('' f

)2(.............6.9)7(9)5.4(5.2 '''' equff

Cubic Splines - Example

Solve the two equations:

The first interval (i=1), apply for the equation:

53308.1)7(,67909.1)5.4(6.9)7(9)5.4(5.2

6.9)7(5.2)5.4(8''''

''''

''''

ffyeild

ff

ff

i

ii

i

1

1

''

1

11

''

1

1

3

1

1

''3

1

1

''

6

)()(

6

)()(

6

)(

6

)()(

iiiii

ii

iii

iiii

ii

ii

i

ii

iii

ii

iii

xxxxxf

xx

xfxx

xxxf

xx

xf

xxxx

xfxx

xx

xfxf

)3(24689.0)5.4(6667.1)3(186566.0)( 31 xxxxf

)3(6

)5.1(67909.1

5.1

15.4

6

)5.1(0

5.1

5.2)3(

)5.1(6

67909.1)3(0)( 33

1

xxxxxf i

Cubic Splines - Example

)5.4(6

)5.2(53308.1

5.2

5.2

76

)5.2(67909.1

5.2

1)5.4(

)5.2(6

53308.1)7(

)5.2(6

67909.1)( 33

2

x

xxxxf

)5.4(638783.1)7(29962.0)5.4(102205.0)7(111939.0)( 33

2 xxxxxf

)7(25.0)9(761027.1)9(127757.0)( 3

3 xxxxf

102886.1)5()( 22 fxf

The 2nd interval (i =2), apply for the equation:

The 3rd interval (i =3),

For x = 5:

4 6 8