You are on page 1of 80

CSC475: Numerical Computing

Tanveer Ahmed Siddiqui

Department of Computer Science


COMSATS University, Islamabad
Lecture #12

Theory of Finite Differences

Department of Computer Science 2


Today Covered
,

Department of Computer Science


Background

 Many scientific and engineering observations are


made by conducting experiments in which
physical quantities are measured and recorded.
 For example, to measure g (the acceleration due
to gravity), the following experiment is carried
out.
 A ball is dropped from the top of a 100-m-tall
building. As the object is falling down, the time t
when it passes sensors mounted on the building wall
is recorded.

Department of Computer Science 4


Background

 For example, to measure g (the acceleration due


to gravity), the following experiment is carried
out.
 A ball is dropped from the top of a 100-m-tall
building. As the object is falling down, the time t
when it passes sensors mounted on the building wall
is recorded.

 The data measured in the experiment is given in the


table.

Department of Computer Science 5


Data Points

 Sometimes measurements are made and


recorded continuously with analog devices.
 In most cases, especially in recent years with the
wide use of computers, the measured quantities
are digitized and stored as a set of discrete
points.
 The experimental records are typically referred
to as data points.

Department of Computer Science 6


Kinds of Data Points

 The experimental records are typically referred


to as data points.

 The values of independent variable x is usually


called argument(or abscissa) and the value of
dependent value y is known as
entry(ordinate).
 These data points are
 Equally spaced
 Unequally
Department spaced
of Computer Science 7
Equally Spaced data

 The difference between two successive values of


abscissa( x values of data points) is constant,
say h. That is step size is constant.
 Mathematically, if x takes values
x0 , x1 , x2 , , xn ,
 then

 Examples

Department of Computer Science 8


Equally Spaced data

 Mathematically, if x takes values

Department of Computer Science 9


Unequally Spaced data

 The difference between two successive values of


abscissa(x values of data points) is not constant.
That is step size varies.
 Examples:

Department of Computer Science 10


Extrapolation

 Once the data is known, scientists and engineers


can use it in different ways.
 Sometimes the data points are used for
estimating a value beyond the range of data
points.
 This is done by extrapolation
 For example estimating value at x = 25 from
following data:

Department of Computer Science 16


Interpolation

 Once the data is known, scientists and engineers


can use it in different ways.
 Sometimes the data points are used for estimating the
expected values between the known points.
 This is done by Interpolation
 For example estimating value at x = 5 from
following data:

 Interpolation is done with the help of finite


differences.
Department of Computer Science 17
DIFFERENCE OPERATORS
AND
DIFFERENCE TABLE

Department of Computer Science 19


Finite difference

 A finite difference is a mathematical expression


of the form:
f(x+ b) – f(x + a).
 The word finite refers to the finite size of the
increments used in the data points.
 The calculus of finite differences deals
with the changes that take place in the
value of a function due to finite changes in
the independent variable.
 Let y0, y1, y2, . . . . . . . , yn be a set of values of any
function y = f( x ).

Department of Computer Science 20


Finite difference

 How we compute this finite difference?


 There are various difference operators to
compute the finite differences.
 These operators operates whether data points
are
 Equally spaced
 Unequally spaced

Department of Computer Science 21


Difference operators for equally spaced data

 An operator is not a number, but it is an


operation, which when applied to a function
changes it to some other function.
 The operator technique proves to be a most
useful tool when we wish to construct formulas
for:
 Interpolation
 Numerical differentiation
 Numerical integration etc.

Department of Computer Science 22


Difference operators for equally spaced data

 The following operators are commonly used:

Department of Computer Science 23


Difference operators: Shift Operator

 Let us first revise the definitions of various


difference operators.
 Shift Operator, E: The shift operator is defined
as:

or
 Hence, shift operator sifts the function value yi
to the next higher value yi +1.
 The second shift operator gives

Department of Computer Science 24


Difference operators: Shift Operator

E is linear and obeys the law of indices.


Generalizing

Department of Computer Science 25


Difference operators: Inverse Shift

 Inverse Shift Operator, E-1:


 The inverse operator E-1 is defined as
1
E f ( x)  f ( x  h)
 Similarly
n
E f ( x)  f ( x  nh)

Department of Computer Science 26


Forward difference operators on function

 For a given function y = f (x), the forward


difference operator denoted as ∆ is defined as
follows:

 This difference is called first difference of the


function y.
 Here, ∆ is called the first difference operator.

Department of Computer Science 27


Forward difference operators on function

 We get the second order differences (denoted by


∆2) when is operated twice on f(x), Thus

 Similarly, ∆3, ∆4, ∆n, may be calculated

Department of Computer Science 28


Example

Department of Computer Science 29


Your Turn

Department of Computer Science 30


Forward difference operators on data points

 For a given table of values (xk , yk ), k = 0,1,


2,..., n with equally spaced abscissas of a
function y = f (x),

we define the forward difference operator ∆ as


follows:
∆yi = yi +1 − yi , i = 0,1,...,(n −1)
 To be explicit, we write
 ∆y 0 = y1 − y0
 ∆y1 = y2 − y1
 ∆y =y −y
Department of Computer Science 31
Forward difference operators on data points

 This difference is called first difference of the


function y and are denoted by the symbol ∆yi.
 Here, ∆ is called the first difference operator.

Department of Computer Science 32


Forward difference operators on data points

 Similarly, the differences of the first differences


are called second differences, defined by
2 y0  y1  y0 , 2 y1  y2  y1

 Thus, in general

 yi  yi 1  yi
2

 Here ∆2 is called the second difference operator

Department of Computer Science 33


Forward difference operators on data points

 Thus, continuing, we can define, rth difference of


y, as
 r yi   r 1 yi 1   r 1 yi

Department of Computer Science 34


Forward difference operators on data points

 For a given table of values (xk , yk ), k = 0,1,


2,..., n with equally spaced abscissas of a
function y = f (x), we define the forward
difference operator ∆ as follows
∆yi = yi +1 − yi , i = 0,1,...,(n −1)
 To be explicit, we write
 ∆y 0 = y1 − y0
 ∆y1 = y2 − y1
 ∆yn −1 = yn − yn-1

Department of Computer Science 35


Forward difference Table

 The previously defined differences can be


written down systematically by constructing a
difference table:

Department of Computer Science 36


Forward difference Table

 Note that the subscript remains constant along


each diagonal of the table.

Department of Computer Science 37


Forward difference Table

 The first term in the table, that is y0 is called the


leading term, while the differences
y0 ,  2 y0 , 3 y0 ,...
are called leading differences

Department of Computer Science 38


Example-1

 Construct a diagonal difference table for the


following set of values:

Department of Computer Science 39


Your Turn

 Construct a diagonal difference table for the


following set of values:

Department of Computer Science 40


Example - 2

Department of Computer Science 41


Some Obvious results

 The nth differences of an exact polynomial of


degree n are constant(see previous slide).
 For n data points, there is a polynomial of degree (n-
1), so for n data points (n-1)th differences are
constant
 The (n+1)st differences of that polynomial are
zero(see previous slide).
 The above values are only true of polynomials
when they are tabulated at equal intervals.
 If the function does not represent an exact
polynomial, the above results will not hold.
Department of Computer Science 42
Some Obvious results

 The nth differences of an exact polynomial of


degree n are constant.
 The (n+1)st differences of that polynomial are
zero.
 The above values are only true of polynomials
when they are tabulated at equal intervals.
 If the function does not represents an exact
polynomial, the above results will not hold.

Department of Computer Science 43


Your Turn

Department of Computer Science 44


Properties Forward difference Operator

Department of Computer Science 45


Properties of Forward difference Operator

Department of Computer Science 46


Upshot

Department of Computer Science 47


Example

 Express ∆2y0 and ∆3y0 in terms of the values of


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

Department of Computer Science 48


Example

Department of Computer Science 49


Forward difference table

Department of Computer Science


Example

 Show that the value of yn can be expressed in


terms of the leading value y0 and the leading
differences
 Solution

Department of Computer Science 51


Example

Department of Computer Science 52


r 1 r 1
 yi  
r
yi 1   yi

Department of Computer Science 53


Finding the missing terms
 Using the difference operators and shifting
operator we can be able to find the missing
terms.
 From the following table find the missing value

 Since only four values of f(x) are given, the


polynomial which fits the data is of degree three.
Hence fourth differences are zeros.

Department of Computer Science 54


Example

Department of Computer Science 55


Excersise 2
 Estimate the production for 1964 and 1966 from
the following data

 Since five values are given, the polynomial


which fits the data is of degree four.

Department of Computer Science 56


Department of Computer Science 57
Binomial Expansion

Department of Computer Science 58


Backward difference operator on function

Department of Computer Science 59


Backward difference operators on data points

 For a given table of values (xk , yk ), k = 0,1,


2,..., 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
yi  yi  yi 1i  n, (n  1), ,1

y1  y1  y0
y2  y2  y1

yn  yn  yn 1
Department of Computer Science 60
Difference between Forward and Backward difference operators

 Forward Backward
yi  yi  yi 1i  n, (n  1), ,1

y0  y1  y0 y1  y1  y0
y1  y2  y1 y2  y2  y1

yn 1  yn  yn 1 yn  yn  yn 1

Department of Computer Science 61


Backward difference Table

Department of Computer Science 62


Example

 Form the backward Difference Table for the


given set of values:

 Solution: Backward Difference Table

Department of Computer Science 63


Example

 Form the backward Difference Table for the


given set of values:

Department of Computer Science 64


Example

 Show that the value of y can be expressed in


terms of yn and its backward differences
 Solution

Department of Computer Science 65


Department of Computer Science 66
Department of Computer Science 67
Difference table

Department of Computer Science 68


Department of Computer Science 69
Department of Computer Science 70
Error propagation in a difference table

 If any entry of the difference table is erroneous,


then this error spread over the table in convex
manner (fan wise pattern)
 If there is any error in a single entry of the
table, then we can detect and correct it from
the difference table. The position of the error in
an entry can be identified by Performing few
steps

Department of Computer Science 71


Department of Computer Science 72
Error propagation in a difference table
 Let us assumed that y3 be erroneous and the
amount of the error be ε.

Department of Computer Science 73


Department of Computer Science 74

Zero

Department of Computer Science 75


Steps to identify error
 If at any stage, the differences do not follow a
smooth pattern, then there is an error.
 If the differences of some order (it is generally
happens in higher order) becomes alternating in
sign then the middle entry contains an error.

Department of Computer Science 76


Example
 values of a polynomial of degree five. It is given
that f (4) is in error. Correct the value of f (4).

 It is given that y = f (x) is a polynomial of


degree five. Hence Δ5y must be a constant and
f (4) is in error.

Department of Computer Science 77


Example cont…
 Let –5.5250 + ∈ be the true or correct value.
The difference table is

Department of Computer Science 78


Department of Computer Science 79
Department of Computer Science 80
Your turn
 Find location of error

The location of an error is obviously centered on 0.060 in the third


difference. Instead of 9.214, one has wrongly entered it as 9.241.

Department of Computer Science 81


With two or more errounous values

Department of Computer Science 82


Department of Computer Science 83
Department of Computer Science 84
 Error = Largest value in a column /
Corresponding coefficient of ε in that column

Department of Computer Science 85


Example
 The corresponding coefficient
of ε in that column
for 0.095 is −10.
 So error will be −0.0095.
 And hence Corrected
Value =0.589+0.0095=0.5985

Department of Computer Science 86

You might also like