ICT114 Mathematics For Computing: Interpolation

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

Centre for Computer Technology

ICT114
Mathematics for
Computing
Week 12

Interpolation

Curve Fitting
A relation between two variables is
expressed mathematically by an equation
connecting both.
Finding equations approximating curves
that fit the given set of data is called curve
fitting.

March 20, 2012

Copyright Box Hill Institute

Objectives
Review week 11
Problem of Interpolation
Finite Differences Diagonal difference
table
Newtons Forward Interpolation
Newtons Backward Interpolation
Lagranges Interpolation

March 20, 2012

Copyright Box Hill Institute

Method of Least Squares (1)


For the data points (x1, y1), (x2,y2),
.(xn,yn)
Let y = a+bx is the least squares line
a and b are determined by solving the
(normal) equations
y = an + b x
xy = a x + b x2

March 20, 2012

Copyright Box Hill Institute

Method of Least Squares (2)


( y) (x2) ( x) (xy)
a = --------------------------------------------n x2 (x)2

n xy ( x)( y)
b = ---------------------------------------------n x2 (x)2
March 20, 2012

Copyright Box Hill Institute

Centre for Computer Technology

Newtons
Forward/Backward
Interpolation

Problem of Interpolation
The following table gives
the value of logx for certain
values of x
To determine the value of
logx for x = 96.45 (which is
not given in the table), we
use the method of
Interpolation.

March 20, 2012

Copyright Box Hill Institute

y=logx

95
96
97
98
99

1.9777
1.9823
1.9868
1.9912
1.9956

Finite Differences Diagonal


Difference Table
In the table in the next slide
a any argument (for x)
h any positive constant
f(x) = f(x+h) f(x) = first difference
f(a) is called the leading term
f(a), 2f(a), 3f(a) are called the leading
differences
March 20, 2012

Copyright Box Hill Institute

Argument

Entry

f(x)

f(a)

1st
Difference
f(x)

2nd
3rd
Difference Difference
2f(x)
3f(x)

f(a)
a+h

2f(a)

f(a+h)

f(a+h)
a+2h

2f(a+h)

f(a+2h)
f(a+2h)

a+3h
March 20, 2012

3f(a)

f(a+3h)
Copyright Box Hill Institute

Newton's Forward Interpolation


u = (x x0)/h
(x) = (x0+uh)
= y0 + u.y0 + u(u-1)/2! .2y0 + ..
.+ u(u-1)(u-2).(u-n+1)/n! .ny0
y0 = f(x0)
March 20, 2012

Copyright Box Hill Institute

Newtons Backward Interpolation


u = (x xn)/h
(x) = (xn+uh)
= yn + u.yn-1 + u(u+1)/2! .2yn-2 + ..
.+ u(u+1)(u+2).(u+n-1)/n! .ny0
yn = f(xn)
March 20, 2012

Copyright Box Hill Institute

Example

From the following


table determine the
value of e0.1245 and
e0.1895
The first step is to
construct the diagonal
difference table

March 20, 2012

Copyright Box Hill Institute

y=ex

0.12
0.13
0.14
0.15
0.16
0.17
0.18
0.19

1.127497
1.138828
1.150274
1.161834
1.173511
1.185305
1.197217
1.209250

y=ex

0.12

1.127497

2 y

0.011331
0.13

1.138828

0.000115
0.011446

0.14

1.150274

0.000114
0.011560

0.15

1.161834

0.000117
0.011677

0.16

1.173511

0.000117
0.011794

0.17

1.185305

0.000118
0.011912

0.18

1.197217

0.000121
0.012033

0.19

1.209250

To determine e0.1245 we have to interpolate at the


beginning of the table.

h = 0.01, x0 = 0.12, x = 0.1245


so, u = (0.1245 0.12)/0.01 = 0.45
therefore,
f(0.1245) =y0 + u.y0 + u(u-1)/2! .2y0
= 1.127497 + 0.45 x 0.011331
+ 0.45 x (0.45-1) /2! x 0.000115
= 1.13258172
Actual value = 1.13258202
March 20, 2012

Copyright Box Hill Institute

To determine e0.1895 we have to interpolate at the


end of the table.
h = 0.01, xn = 0.19, x = 0.1895
so, u = (0.1895 0.19)/0.01 = -0.05
therefore,
(0.1895) =yn + u.yn-1 + u(u+1)/2! .2yn-2

= 1.209250 + (-0.05) x 0.012033


+(-0.05)(-0.05+1) / 2! x 0.000121
= 1.20864548

Actual value = 1.208645124


March 20, 2012

Copyright Box Hill Institute

Question
Find the value of
log(96.45) and
log(98.75)
using Newton's interpolation formulae from
the table given in the second slide.
Compare them with the actual value.

March 20, 2012

Copyright Box Hill Institute

Centre for Computer Technology

Lagranges Interpolation

Lagranges Interpolation
Newtons formulae can only be used for
equidistant values of the argument
But sometimes it is difficult to obtain
tabulated values of a function for
equidistant values of the argument.
To deal with such a situation we use
Lagranges interpolation formula

March 20, 2012

Copyright Box Hill Institute

The Lagranges Interpolation formula is given below


(x-x1)(x-x2)..(x-xn)
(x) = --------------------------------- y0
(x0-x1)(x0-x2)(x0-xn)
(x-x0)(x-x2)..(x-xn)
+ ---------------------------------- y1 +
(x1-x0)(x1-x2)(x1-xn)

(x-x0)(x-x2)..(x-xn-1)
+ --------------------------------- yn
(xn-x0)(xn-x2)(xn-xn-1)
March 20, 2012

Copyright Box Hill Institute

Example
From the given table find the value of y for x = 3.743
x0 = 3.7428037, y0 = 5531
x1 = 3.7428822, y1 = 5532
x2 = 3.7429607, y2 = 5533
x3 = 3.7430392, y3 = 5534
x4 = 3.7431176, y4 = 5535
x = 3.743
March 20, 2012

3.7428037
3.7428822
3.7429607
3.7430392
3.7431176

5531
5532
5533
5534
5535

Copyright Box Hill Institute

(x-x1)(x-x2)(x-x3) (x-x4)
(x) = ---------------------------------- y0
(x0-x1)(x0-x2)(x0-x3)(x0-x4)

(0.0234250 x 5531)

(x-x0)(x-x2)(x-x3)(x-x4)
+ ------------------------------------ y1 +
(x1-x0)(x1-x2)(x1-x3)(x1-x4)

(-0.156157 x 5532)

(x-x0)(x-x1)(x-x3)(x-x4)
+ ------------------------------------ y2 +
(x2-x0)(x2-x1)(x2-x3)(x2-x4)

(0.702259 x 5533)

(x-x0)(x-x1)(x-x2)(x-x4)
+ ------------------------------------ y3 +
(x3-x0)(x3-x1)(x3-x2)(x3-x4)

(0.469666 x 5534)

(x-x0)(x-x1)(x-x2)(x-x3)
+ ------------------------------------ y4
(x4-x0)(x4-x1)(x4-x2)(x4-x3)

(-0.0391929 x 5535)

March 20, 2012

Copyright Box Hill Institute

y = (3.743)
= (0.0234250 x 5531)
+ (-0.156157 x 5532)
+ (0.702259 x 5533)
+ (0.469666 x 5534)
+ (-0.0391929 x 5535)

= 5533.501
March 20, 2012

Copyright Box Hill Institute

Question
From the given table find the value of y for x = 0.135

March 20, 2012

0.12
0.13
0.14
0.15

1.127497
1.138828
1.150274
1.161834

Copyright Box Hill Institute

Summary
Newtons Forward Interpolation formula
u = (x x0)/h

(x) = (x0+uh)
= y0 + u.y0 + u(u-1)/2! .2y0 + ..
.+ u(u-1)(u-2).(u-n+1)/n! .ny0
y0 = f(x0)
March 20, 2012

Copyright Box Hill Institute

Summary
Newtons Backward Interpolation formula

u = (x xn)/h
(x) = (xn+uh)
= yn + u.yn-1 + u(u+1)/2! .2yn-2 + ..
.+ u(u+1)(u+2).(u+n-1)/n! .ny0

yn = f(xn)
March 20, 2012

Copyright Box Hill Institute

Summary
The Lagranges Interpolation formula is given below
(x-x1)(x-x2)..(x-xn)
(x) = --------------------------------- y0
(x0-x1)(x0-x2)(x0-xn)

(x-x0)(x-x2)..(x-xn)
+ ---------------------------------- y1 +
(x1-x0)(x1-x2)(x1-xn)

(x-x0)(x-x2)..(x-xn-1)
+ --------------------------------- yn
(xn-x0)(xn-x2)(xn-xn-1)
March 20, 2012

Copyright Box Hill Institute

References

H L Verma and C W Gross : Introduction to


Quantitative Methods,John Wiley
JB Scarborough : Numerical Mathematical
Analysis, Jon Hopkins Hall, New Jersey
Gerald W. Recktenwald, Numerical Methods
with MATLAB, Implementation and Application,
Prentice Hall
Murray Spiegel, John Schiller, Alu Srinivasan,
Probability and Statistics, Schaums easy
Outlines
http://mathworld.wolfram.com

March 20, 2012

Copyright Box Hill Institute

You might also like