0% found this document useful (0 votes)
79 views

Chapter 1 Numerical Interpolation and Differentiation

The document discusses numerical interpolation and integration. It introduces interpolation as a way to obtain intermediate values from discrete data points. Interpolation is used to fit curves through data and can be done using polynomials, with higher degree polynomials allowing for better fits. Difference tables are presented as a way to derive interpolation polynomials, where taking higher order differences of a polynomial function will result in constant values. Newton-Gregory polynomials provide a specific formula for polynomial interpolation of evenly spaced data points.

Uploaded by

zzz_monster
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Chapter 1 Numerical Interpolation and Differentiation

The document discusses numerical interpolation and integration. It introduces interpolation as a way to obtain intermediate values from discrete data points. Interpolation is used to fit curves through data and can be done using polynomials, with higher degree polynomials allowing for better fits. Difference tables are presented as a way to derive interpolation polynomials, where taking higher order differences of a polynomial function will result in constant values. Newton-Gregory polynomials provide a specific formula for polynomial interpolation of evenly spaced data points.

Uploaded by

zzz_monster
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

NUMERICAL INTERPOLATION

AND INTEGRATION

CONTENT
Page

1.1 Introduction ....................................... 1

1.2 Difference Table .............................. 4

1.3 Newton-Gregory Polynomials .... 16

1.4 Derivatives From Interpolations . 29


1.1 INTRODUCTION

• You may require estimates at points


between the calculated discrete values.

For e.g. in numerical modelling of deep


beam, plane stress elements are used. The
displacements and strains are worked out at
the internal points known as Gaussian
points. These values are then interpolated
to the corner nodes and mid-side nodes.

• You may require a simplified version of a


complicated function.

• You may require to provide a statistical


equation to a group of data.

Basically, there are two approaches to


numerical analysis of data, depending on the
data themselves.

Firstly, where the data themselves inherit


significant degree of error, we derive a single
1
curve that represents the general trend of the
data. This is a statistical approach.

This type of analysis is known as least-squares


regression.

Secondly, where the data are known to be very


accurate, we fit a curve that passes directly
through each of the points. This is interpolation
which we shall cover first.

2
Y

Interpolation can be used to obtain


intermediate values from discrete data points.
Interpolation is also relevant to numerical
integration and nnumerical solution of O.D.E.
and and

These topics will be covered in later part of the


course. In fact, interpolation forms the
backbone of Computational Methods.

3
1.2 DIFFERENCE TABLE

EXAMPLE 1: POLYNOMIAL FUNCTION

The difference table for a polynomial function


e.g. f(x) = x3 is shown below. What do you
notice ?
xi f(xi) ∆f ∆2f ∆3f ∆4f
-3 -27
19
-2 -8 -12
7 6
-1 -1 -6 0
1 6
0 0 0 0
1 6
1 1 6 0
7 6
2 8 12
19
3 27

4
∆fi = f(xi+1) - f(xi)

where ∆ = forward difference operator

Note: For a 3rd degree polynomial, the 3rd


order differences are constant.

Corollary:

• If the nth order differences are constant, we


can approximate f(x) by an nth degree
polynomial function Pn(x).

5
EXAMPLE 2: NON-POLYNOMIALS

The difference table for a non-polynomial


function, e.g. f(x) = 1/x, is shown below. What
can you infer from the difference columns ?

x f(x) ∆f ∆2 f ∆3f
1.0 1.0000
-0.1667
1.2 0.8333 0.0477
-0.1190 -0.0180
1.4 0.7143 0.0297
-0.0893 -0.0098
→1.6 0.6250 0.0199
-0.0694 -0.0061
1.8 0.5556 0.0138
-0.0556
2.0 0.5000

Note: 3rd order differences fluctuate wildly,


although the values are small.
6
Corollaries:

• For non-polynomial functions, the nth order


of differences may be small as n increases,
but the differences themselves will not be
constant.

• If the nth order differences are constant, the


underlying function must be a polynomial of
degree n.

7
NOTATIONS FOR DIFFERENCES

Forward differences:

A polynomial function can be written in two


forms:

(a) Pn(x) = ao + a1 x + a2 x2 + ... + an xn

(evenly-spaced data)

(b) Pn(x) = ao + a1 (x-xo) + a2 (x-xo)(x-x1) +


...
+ anxn (x-xo)(x-x1) .. (x-xn-1)

(unevenly-spaced data)

8
x f(x) 1st 2nd 3rd 4th
x-2 f-2
∆f-2
x-1 f-1 ∆2f-2
∆f-1 ∆3f-2
xo fo ∆2f-1 ∆4f-2
∆fo ∆3f-1
x1 f1 ∆2fo
∆f1
x2 f2

Note: ∆ f-2 = f-1 - f-2 ,

∆2f-2 = ∆ f-1 - ∆ f-2

∆ f-1 = fo - f-1 ,

∆2f-1 = ∆ fo - ∆ f-1

9
Generally,
∆fm = fm+1 - fm

∆2fm = ∆fm+1 - ∆fm

From Eg.2, if we choose the starting point

xo = 1.6,

fo = 0.6250

∆fo = -0.0694

∆2fo= 0.0138

10
EXAMPLE 3: EFFECT OF ERRORS IN X
∆f ∆ f ∆ f ∆ f
2 3 4
x f(x)
0 1
32
2 33 160
192 133
4 225 293 44
485 177
6 710 470 -66
955 111
8 1665 581 44
1536 155
10 3201 736 -11
2272 144
12 5473 880 0
3152 144
14 8625 1024
4176
16 12801

11
If one of the x data in the difference table is
wrong, but we know that the underlying
function is cubic degree beforehand, from the
difference columns, we may be able to undo
the error, and find the correct value for x.

(For comparison purpose, the actual function is


3 2
3x + 2x + 1. )

• We would need at least one of the elements


in the fourth order difference to be zero.

• Then we can perform a “reverse engineering”


to back calculate the third order differences
which should be constant.

• Working from the third order differences, we


proceed to the second order differences and
so forth, and finally zoom in on the wrong x.

• All these are only possible, if we already


know the degree of the underlying function.

12
∆f ∆f ∆f ∆f
2 3 4
x f(x)

144
304 0
496 144
6 721 448 0
944 144
592 0
144
0

13
Notations for differences.

∆ fi ∆(∆fi) ∆(fi+1 - fi)


2
= =

= ∆fi+1 - ∆fi

= fi+2 - fi+1 - (fi+1 - fi)

∴ ∆ fi
2
= fi+2 - 2fi+1 + fi

∆ fi
3
Verify = fi+3 - 3fi+2 + 3fi+1 - fi

The coefficients can be obtained from the


Pascal Triangle analogy:

+1
2
+1 -2 +1 ∆
3
+1 -3 +3 -1 ∆
4
+1 -4 +6 -4 +1 ∆

14
Forward Difference method

∆fi = fi+1 - fi

∆2fi = ∆ (∆fi) etc. etc.

Homework:

Verify ∆ fi =
4
fi+4 - 4fi+3 + 6fi+2 - 4 fi+1 + fi

15
1.3 NEWTON-GREGORY
POLYNOMIALS

It is noteworthy that the Newton-Gregory


method applies to only evenly spaced data,
i.e. x with uniform increment. For
unevenly spaced data, we need to use
Newton divided difference.

Linear Interpolation

h
f1 - fo

sh

fo f1
X

xo x x1

16
The curve f(x) is approximated by a CHORD at
two adjacent x-values, xo and x1.

Using Similar Triangle, f(x) can be


approximated by a linear function P1(x) :

f(x) ≈ P1(x)

= fo + (x - xo)/h (f1 - fo)

= fo + s ∆fo

x - xo
where s =
h

17
Quadratic Interpolation
(evenly-spaced data)

f(x)
P2(x)
f2 - fo

sh f1 f2
fo
h h X

xo x x1 x2

This time, f(x) is approximated by a quadratic


function P2(x), passing through three points
(xo, fo), (x1, f1) and (x2, f2).

f(x) ≈ P2(x) = fo + s ∆fo +

s( s − 1) 2
∆ fo
2

x - xo
where s =
h

18
At x = xo , s= 0 ,

P2(xo) = fo

At x = x1 , s= 1 ,

P2(x1) = fo + ∆ fo = f1

At x = x2 , s= 2 ,

P2(x2) = fo + 2∆ fo + ∆ fo
2

= f1 + ∆ f1 = f2
2
(Note: ∆ fo = ∆ f1 - ∆ fo )

Newton-Gregory Forward Interpolation


Formula

Pn(x) = fo + s ∆ fo + s ( s − 1 ) ∆2 f + .....
o
2!

⎛ s⎞ 2
= fo + ⎛ s⎞
⎜ ⎟ ∆ fo + ⎜ ⎟ ∆ fo + ......
⎝ 1⎠ ⎝ 2⎠
19
EXAMPLE 4: EXACT INTERPOLATION

In this example, we are trying to find a suitable


polynomial function which fits exactly with the
data in the table.

f(x) ∆f ∆f ∆f ∆f
2 3 4
x
0 0
1
1 1 12
13 12
2 14 24 0
37 12
3 51 36 0
73 12
4 124 48
121
5 245

Using cubic forward interpolation


20
s( s − 1) 2
P3(x) = fo + s∆ fo + ∆ fo
2!

s( s − 1)( s − 2) 3
+ ∆ fo
3!

Choose xo = 0 , s = (x/1) = x

x( x −1)
P3 (x) = 0 + x.1 + 2 . 12 +

x( x − 1)( x − 2)
. 12
6
3
= 2x - x

21
Corollaries:

• If fn(x) can be exactly approximated by Pn(x)


th
(i.e. it requires n degree polynomial), then
there is one and only one Pn(x) that fits fn(x) -
this comes from the Uniqueness Theorem.

EXAMPLE 5: FINDING THE STARTING


POINT

Find f(3.2) in Eg. 4 using quadratic


interpolation ( n = 2).

Forward Interpolation

A quadratic curve will pass through 3 points


(xo, yo), (x1, y1), and (x2, y2). To minimise
errors, fit the mid-point as close to x = 3.2 as
possible. In this case we choose x1 = 3 , thus ,
xo = 2 .

22
3.2 − 2
∴ s = = 1.2
10
.

s( s − 1) 2
Thus, f(3.2) ≈ fo + s ∆ fo + ∆ fo
2

(1.2)(0.2)
= 14 + 1.2(37) + 36
2

= 62.72 ( cf. to 62.336 from


f(x) = 2x3 - x )

s( s − 1)( s − 2 )
Error Term = 12 = - 0.384
6

Truncation Errors

Recall Newton-Gregory forward difference:

s( s − 1) 2
f(x) ≈ fo + s∆ fo + ∆ fo + .... +
2!

23
s( s − 1)...( s − n + 1) n
∆ fo
n!

Corollaries

• Error εn(x) is of the order of magnitude of


the next difference not used in Pn(x).

• One should choose xo, x1 ... xn such that the


value x at which one interpolates is as well
centred as possible among xo, ... xn given in
the Table.

• We can approximate the error term fn+1(ξ)


∆n+1 f (ξ )
by h n+1

24
EXAMPLE 6: FINDING BEST
ESTIMATE

Find the best estimates and the associated


truncation errors of f(0.8) using Newton
Gregory forward difference formula via:

(a) quadratic interplation.

(b) cubic interpolation.

∆f ∆f ∆f ∆f
2 3 4
x f(x)
0.1 0.09983
0.37960
0.5 0.47943 -0.07570
0.30390 -0.04797
0.9 0.78333 -0.12367 0.01951
0.18023 -0.02846
1.3 0.96356 -0.15213
0.02810
1.7 0.99166

25
(a) Quadratic interpolation

3 points are required (xo, fo), (x1, f1) and


(x2, f2) for n = 2..

Choose x1 = 0.9 ⇒ xo = 0.5

x - xo 0.8 - 0.5
s = = = 0.75
h 0.4

s( s − 1) 2
f(x) ≈ fo + s∆ fo + ∆ fo + ....
2!

f(0.8) ≈0.47943+0.30390(0.75)+

( − 0.12367 )(0.75)( − 0.25)


2!

= 0.71895

s( s − 1)( s − 2)
ε2 (x) = (- 0.02846)
3!

26
= - 0.00111

(b) Cubic interpolation

4 points are required i.e. (xo, fo), (x1, f1), (x2,


f2) and (x3 , f3).

Locate x = 0.8 between x1 = 0.5 and x2 =


0.9.

⇒ xo = 0.1

0.8 - 0.1
∴ s = = 1.75
0.4

s( s − 1) 2
f(x) ≈ fo + s∆ fo + ∆ fo +
2!

s( s − 1) ( s-2) 3
∆ fo
3!

27
f(0.8) = 0.09983 + 1.75 (0.3796)

(1.75)(0.75)(-0.0757)
+
2

. (0.75)(- 0.25)
175
+ (- 0.04797)
6
= 0.71707

s ( s − 1 )( s − 2 )( s − 3 )
ε3 (x) = (0.01951 )
4!

= 0.00033

28
1.4 DERIVATIVES FROM INTERPOLATION

Y Numerical Integration
f(x)

Pn(x)

• Find area under a series of tabulated points.

Numerical Differentiation
Y f(x)

f’(x)

P’n(x) Pn(x)

• Find the gradient at the discrete given


points (xi, yi)
• In both cases analytical functions are not
known, thus we rely completely on
tabulated data points (xi, yi).

29
Consider the Newton-Gregory Forward
Interpolation:

s( s − 1) 2
Pn(x) = fo + s∆ fo + ∆ fo + ..
2!
+ Error

On differentiating,

d ds d
Pn' (x) = [Pn(x)] + [εn(x)]
ds dx dx

d ds 1 ⎧ 1
ds
[Pn(x)] = ⎨ ∆f o +
dx h ⎩ 2
[( s − 1) + s]∆2 f o

1 ⎫
+ [ ( s − 1)( s − 2 ) + s( s − 2 ) + s( s − 1) ] o
∆3
f + " ⎬
6 ⎭

30
For one-sided forward difference, at a specific
point, x = xo, ∴s = 0.

1⎧ 1 2 1 3 ⎫ d
P ' n ( x o ) = ⎨∆f o − ∆ f o + ∆ f − ..⎬ + [ε n ( x )]
h⎩ 2 3 ⎭ dx

(1)

The nth term in the bracket of Eq(1)

( − 1)n −1 ∆n f o
=
n

Thus, Eq (1) gives the derivative of function at


xo using an nth degree polynomial passing
through (xo, fo) and n additional points to the
right. That is why it is known as one-sided
forward difference.

31
EXAMPLE 7: DIFFERENCE TABLE

Obtain f'(0) from the data below.


(The data are generated using f(x) = ex ) .

x f ∆f ∆2f
0.0 1.000000
0.105172
0.1 1.105172 0.011059
0.116231
0.2 1.221403 0.012225
0.128456
0.3 1.349859

We know that the exact value

f'(0) = 1.00

32
Numerically, using 1 term only:

1
f'(0) = {∆ fo }
0.1

⎛ 1 × 0.105172 ⎞
= ⎜ ⎟
⎝ 0.1 ⎠

= 1.05172

Using 2 terms:

⎛ 1 2 ⎞
1⎜ ∆f o − ∆ f o ⎟
⎝ 2 ⎠
f'(0) =
0 .1

1
= 1.05172 − 0.011059
0.2

= 0.99643

Using 3 terms, verify that f'(0)= 1.00031.

33
Colloraries:

• Although the interpolating formula is exact at


xo (by using the exact order) the derivative at
xo is subject to error.

• The term f'(x) = ∆ fo/h in Eq.(1) is in terms of


finite differences and can be used directly.

Generally, f'(xo) is expressed as:

f'(xo)
1 ⎧⎪ 1 2 1 3 ( − 1) n −1
⎫⎪
= ⎨∆f o − ∆ fo + ∆ fo + " + ∆ fo ⎬
n
h ⎪⎩ 2 3 n ⎪⎭

( − 1) n h n n+1
+ f ( ξ) xo < ξ < xn
(n + 1)
st
1 term on R.H.S. gives an approximation for
f'(xo).
nd
2 term on R.H.S. is the truncation error.

34
EXAMPLE 8: FORWARD DIFFERENCE
DERIVATIES

Obtain the derivative of y at x = 1.7 and


estimate the errors. (The equation is y = ex).

x y ∆y ∆2 y ∆3 y ∆4 y
1.3 3.669
0.813
1.5 4.482 0.179
0.992 0.041
1.7 5.474 0.220 0.007
1.212 0.048
1.9 6.686 0.268 0.012
1.480 0.060
2.1 8.166 0.328 0.012
1.808 0.072
2.3 9.974 0.400
2.208
2.5 12.182

35
1 term
1 1.212
y'(1.7) = ∆ fo = = 6.060
h 0.2

2 terms

y'(1.7)

= 1 ⎛⎜ ∆ f o − 1 ∆2 f o ⎞⎟ = 1 ⎛
⎜ 1.212 −
1 ⎞
0.268⎟
h ⎝ 2 ⎠ 0.2 ⎝ 2 ⎠

= 5.390

4 terms

verify that y'(1.7) = 5.475

36
Y y=ex

y=ln x

For a one-sided forward difference Pn ' (x), it


does not fit those points that are symmetrical
about xo.

TKH
6 Oct 2006

37

You might also like