Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor...

53
BE(Chem. Engg.) 15 batch Numerical Analysis with Computer Applications

Transcript of Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor...

Page 1: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

BE(Chem. Engg.) 15 batch

Numerical Analysis with

Computer Applications

Page 2: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Topic: Interpolation

Page 3: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Finite Difference Operators Newton’s Forward Difference Interpolation Formula Newton’s Backward Difference Interpolation Formula Lagrange’s Interpolation Formula Divided Differences Interpolation in Two Dimensions Cubic Spline Interpolation

Page 4: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Introduction

Page 5: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Finite differences play an important role in numerical techniques, where tabulated values of the functions are available. For instance, consider a function

( ).y f x=

Page 6: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

As x takes values let the corresponding values of y be

0 1 2, , , , ,nx x x x

0 1 2, , , , .ny y y y

Page 7: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

the process of estimating the value of y, for any intermediate value of x, is called interpolation.

That is, for given a table of values, ( , ), 0,1, 2, , ;k kx y k n=

Page 8: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

• The method of computing the value of y, for a given value of x, lying outside the table of values of x is known as extrapolation.

Page 9: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

• If the function f (x) is known, the value of y corresponding to any x can be readily computed to the desired accuracy.

Page 10: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

• For interpolation of a tabulated function, the concept of finite differences is important. The knowledge about various finite difference operators and their symbolic relations are very much needed to establish various interpolation formulae.

Page 11: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Finite Difference Operators

Page 12: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Finite Difference Operators Forward Differences Backward Differences Central Difference

Page 13: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Forward Differences

Page 14: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

( , ), 0,1, 2,...,k kx y k n=

( ),y f x=

For a given table of values

with equally spaced abscissas of a function

we define the forward difference operator as follows ∆

Page 15: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

To be explicit, we write

0 1 0

1 2 1

1 1n n n

y y yy y y

y y y− −

∆ = −

∆ = −

∆ = −

Page 16: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

These differences are called first differences of the function y and are denoted by the symbol Here, is called the first difference operator

iy∆

Page 17: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

• Similarly, the differences of the first differences are called second differences, defined by

2 20 1 0 1 2 1,y y y y y y∆ = ∆ −∆ ∆ = ∆ −∆

Thus, in general 2

1i i iy y y+∆ = ∆ −∆

Page 18: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

2∆Here is called the second difference operator. Thus, continuing, we can define, r-th difference of y, as

1 11

r r ri i iy y y− −

+∆ = ∆ −∆

Page 19: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

• By defining a difference table as a convenient device for displaying various differences, the above defined differences can be written down systematically by constructing a difference table for values

( , ), 0,1,...,6k kx y k =

Page 20: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Forward Difference Table

Page 21: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

•This difference table is called forward difference table or diagonal difference table. Here, each difference is located in its appropriate column, midway between the elements of the previous column.

Page 22: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

•Please note that the subscript remains constant along each diagonal of the table. The first term in the table, that is y0 is called the leading term, while the differences

•are called leading differences

2 30 0 0, , ,...y y y∆ ∆ ∆

Page 23: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Example Construct a forward difference table for the following values of x and y:

Page 24: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Solution

Page 25: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

20y∆ 3

0y∆

Example Express and in terms of the values of the function y.

Page 26: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Solution: Noting that each higher order difference is defined in terms of the lower order difference, we have 2

0 1 0 2 1 1 0

2 1 0

( ) ( )

2

y y y y y y yy y y

∆ = ∆ −∆ = − − −

= − +

Page 27: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

and 3 2 2

0 1 0 2 1 1 0

3 2 2 1 2 1 1 0

3 2 1 0

( ) ( )

( ) ( ) ( ) ( )3 3

yy y y y y yy y y y y y y y

y y y y

∆ = ∆ −∆ = ∆ −∆ − ∆ −∆

= − − − − − + −

= − + −

Hence, we observe that the coefficients of the values of y, in the expansion of , are binomial coefficients.

2 30 0,y y∆ ∆

Page 28: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Thus, in general, we arrive at the following result: -

0 1 1 2 2

3 3 0( 1)

n n nn n n

n nn

y y C y C yC y y

− −

∆ = − +

− + + −

Page 29: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Example Show that the value of yn can be expressed in terms of the leading value y0 and the leading differences

20 0 0, , , .ny y y∆ ∆ ∆

Page 30: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Solution The forward difference table will be

1 0 0 1 0 0

2 1 1 2 1 1

3 2 2 3 2 2

ororor

y y y y y yy y y y y yy y y y y y

− = ∆ = + ∆ − = ∆ = + ∆ − = ∆ = + ∆

Page 31: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Similarly, 2 2

1 0 0 1 0 02 2

2 1 1 2 1 1

or

or

y y y y y yy y y y y y

∆ −∆ = ∆ ∆ = ∆ + ∆

∆ −∆ = ∆ ∆ = ∆ + ∆

Similarly, we can also write 2 2 3 2 2 3

1 0 0 1 0 02 2 3 2 2 3

2 1 1 2 1 1

or

or

y y y y y yy y y y y y

∆ −∆ = ∆ ∆ = ∆ + ∆

∆ −∆ = ∆ ∆ = ∆ + ∆

Page 32: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

2 2 32 0 0 0 0( ) ( )y y y y y∆ = ∆ + ∆ + ∆ + ∆

2 30 0 02y y y= ∆ + ∆ + ∆

3 2 22

1 1 1 12 3

0 0 0 0

( ) ( )

3 3

y y yy y y y

y y y y

= + ∆

= + ∆ + ∆ + ∆

= + ∆ + ∆ + ∆3

0(1 ) y= + ∆

Page 33: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Similarly, we can symbolically write

1 02

2 03

3 0

0

(1 ) ,

(1 ) ,

(1 )........

(1 )nn

y yy yy y

y y

= + ∆

= + ∆

= + ∆

= + ∆

Page 34: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Hence, we obtain 2

0 1 0 2 03

3 0 0

n nnn n

y y C y C yC y y= + ∆ + ∆

+ ∆ + + ∆

00

nn i

n ii

y C y=

= ∆∑

Page 35: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Backward Differences

Page 36: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

For a given table of values ( , ), 0,1, 2,...,k kx y k n=

of a function y = f (x) with equally spaced abscissas, the first backward differences are usually expressed in terms of the backward difference operator as ∇

Page 37: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

1 , ( 1), ,1i i iy y y i n n−∇ = − = −

1 1 0

2 2 1

1n n n

y y yy y y

y y y −

∇ = −∇ = −

∇ = −

OR

Page 38: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

The differences of these differences are called second differences and they are denoted by

2 2 22 3, , , .ny y y∇ ∇ ∇

That is 21 2 1

22 3 2

21n n n

y y yy y y

y y y −

∇ = ∇ −∇

∇ = ∇ −∇

∇ = ∇ −∇

Page 39: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Thus, in general, the second backward differences are

21, , ( 1),..., 2i i iy y y i n n−∇ = ∇ −∇ = −

while the k-th backward differences are given as

1 11, , ( 1),...,k k k

i i iy y y i n n k− −−∇ = ∇ −∇ = −

Page 40: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

These backward differences can be systematically arranged for a table of values

( , ), 0,1,...,6k kx y k =

Backward Difference Table

Page 41: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

From this table, it can be observed that the subscript remains constant along every backward diagonal.

Page 42: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Example Show that any value of y can be expressed in terms of yn and its backward differences.

Page 43: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Solution

1n n ny y y− = −∇ 2 1 1n n ny y y− − −= −∇

21n n ny y y−∇ = ∇ −∇

1 , ( 1), ,1i i iy y y i n n−∇ = − = −

21, , ( 1),..., 2i i iy y y i n n−∇ = ∇ −∇ = −

From

We get

From

We get

Page 44: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

From these equations, we obtain

22 2n n n ny y y y− = − ∇ +∇

Similarly, we can show that 2 3

3 3 3n n n n ny y y y y− = − ∇ + ∇ −∇

Page 45: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Symbolically, these results can be rewritten as follows:

12

23

3

(1 )

(1 )

(1 ).......

(1 )

n n

n n

n n

rn r n

y yy yy y

y y

= −∇

= −∇

= −∇

= −∇

21 2 ( 1)n n r r

n r n n n ny y C y C y y− = − ∇ + ∇ − + − ∇

Page 46: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Central Differences

Page 47: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

In some applications, central difference notation is found to be more convenient to represent the successive differences of a function. Here, we use the symbol to represent central difference operator and the subscript of for any difference as the average of the subscripts

δyδ

Page 48: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

1 2 1 0 3 2 2 1, ,y y y y y yδ δ= − = −

In general (1 2) (1 2)i i iy y yδ + −= −

Higher order differences are defined as follows:

2(1 2) (1 2)i i iy y yδ δ δ+ −= −

1 1(1 2) (1 2)

n n ni i iy y yδ δ δ− −

+ −= −

Page 49: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

These central differences can be systematically arranged as indicated in the Table

Page 50: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Thus, we observe that all the odd differences have a fractional suffix and all the even differences with the same subscript lie horizontally.

Page 51: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

The following alternative notation may also be adopted to introduce finite difference operators. Let y = f (x) be a functional relation between x and y, which is also denoted by yx.

Page 52: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Suppose, we are given consecutive values of x differing by h say x, x + h, x +2h, x +3h, etc. The corresponding values of y are As before, we can form the differences of these values.

2 3, , , ,x x h x h x hy y y y+ + +

Page 53: Numerical Analysis with Computer Applicationsahsheikh.github.io/Courses/NA/fin_diff.pdfFor interpolation of a tabulated function, the concept of finite differences is important. The

Thus ( ) ( )x x h xy y y f x h f x+∆ = − = + −

2x x h xy y y+∆ = ∆ −∆

( ) ( )x x x hy y y f x f x h−∇ = − = − −

( / 2) ( / 2) 2 2x x h x hh hy y y f x f xδ + −

= − = + − −

Similarly