Lec5 Numerical Model
Lec5 Numerical Model
INTERPOLATION
Chapter 18 in Textbook
1
LESSON OUTCOMES
2
APPLICATION
3
INTERPOLATION
Interpolation is a method of constructing new data points
within the range of a discrete set of known data points. It is a
technique to estimate intermediate value within known data
points.
4
INTERPOLATION
•Application: to estimate intermediate values between
precise data points by using polynomial
• Two methods used to derive the polynomial
1. Newton’s Divided-Difference interpolating polynomial
2. Lagrange interpolating polynomial
5
INTERPOLATION
•For n+1 data points, there is one and only one polynomial
of order n that passes through all the points.
y a 0 a1 x y a 0 a1 x a2 x 2 y a 0 a1 x a2 x 2 a3 x3
6
INTERPOLATION
y a 0 a1 x y a 0 a1 x a2 x 2 y a 0 a1 x a2 x 2 a3 x3
NEWTON’S DIVIDED-DIFFERENCE
INTERPOLATING POLYNOMIALS
8
NEWTON’S DIVIDED-DIFFERENCE INTERPOLATING
POLYNOMIALS
• Linear Interpolation
- Simplest form of interpolation is to connect two data
points A[x0, f(x0)] and B[x1,f(x1)] with a straight line.
- Use similar triangle principle on ADE and ABC
DE BC
B
f(x1) AE AC
f(x) f x f x0 f x1 f x0
D or 1
f1(x) x x0 x1 x0
f1(x) f x1 f x0
f1 x f x0 x x0
A E C x1 x0
f(x0)
x0 x x1
or f1 x b0 b1 ( x x0 )
9
NEWTON’S DIVIDED-DIFFERENCE INTERPOLATING
POLYNOMIALS
Linear Interpolation
•Use 1st order (linear) polynomial to connect 2 points with a
straight line; needs to solve 2 unknown: b0 , b1
• General linear interpolation equation: f
f1 ( x) b0 b1 ( x x0 ) ........(1)
x
where b0 = constant = f1(x0)
b1 = 1st order forward
f x1 f x0
Use of
b
difference term 1 square
x1 x0 bracket [ ]
f [ x1 , x0 ] .......(2)
10
CLASS ACTIVITY
f1 ( x) b0 b1 ( x x0 )
Linear
Interpolation f x1 f x0
f1 ( x0 ) ( x x0 ) f1 ( x0 ) f [ x1 x0 ]( x x0 )
x1 x0
11
SOLUTION
Pass through 2 points:
x0 = 0 ; f(x0) = e0.5(0) = 1
x1 = 2 ; f(x1) = e0.5(2) = 2.7183
Find f (1) = ?
Liner model: f (x) = b0 + b1(x x0)
Substituting: b0 = f(x0) = 1
13
NEWTON’s DIVIDED DIFFERENCE -
Quadratic Interpolating polynomial
•If 3 data points are available as [x0, f(x0)], [x1, f(x1)] and
[x2, f(x2)], then we can use a second-order (quadratic)
polynomial to fit the data
•Curvature is introduced into the line connecting the points
if higher order polynomials are used
• For example: 2nd-order (quadratic) interpolation formula:
14
To find b0, b1 and b2
To find Set
solving: b0 = f (x0 )
To find Set
f (x1 )= b0 + b1(x1 x0) + b2(x1 x0 )(x1 x1)
f ( x1 ) f ( x0 ) Use of square
solving : b1 f [ x1 , x0 ] bracket [xj, xi] as
( x1 x0 ) difference term
15
To find b0, b1 and b2
Finally to find b2 , set x = x2
f (x2 )= b0 + b1(x2 x0) + b2(x2 x0 )(x2 x1)
f x1 f x0
b1 =1st order
forward difference b1 f [ x1 , x0 ]
term x1 x0
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
b2 = 2nd order forward
b2
x 2 x1 x 1 x0
x2 x0 difference term
f [ x2 , x1 ] f [ x1 , x0 ]
f [ x2 , x1 , x0 ]
x2 x0
The closer is your data interval, the more accurate is your interpolation
16
CLASS ACTIVITY
Develop a quadratic Newton’s interpolation formula for
function f(x) = e0.5x using values at x0 = 0 and x1=2 and
x2=4. Evaluate f(1) and compute the true error t .
x 0 2 4 Find f(1) = ?
y 1 2.7183 7.3891
Substituting: b0 = f(x0) = 1
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
f x1 f x0 2.7183 1
b1 0.8592
b2
x x x x
x1 x0 20
2 1 1 0
x2 x0
(7.3891 2.7183)
0.8592
( 4 2)
0.3691
( 4 0)
19
NEWTON DIVIDED DIFFERENCE –
General form of nth order polynomial
20
General form of nth order polynomial
2nd order difference
f xk , xk 1 f xk 1 , xk 2
f xk , xk 1 , xk 2
xk xk 2
21
**n-th order difference term
Computing Newton’s divided differences using difference table:
Third order
First order Second order Fourth order
divided
xk yk=f [xk] divided difference divided difference divided
Difference
f[xj, xi] f[xk, xj, xi] f[xl, xk, xj, xi]
difference
x0 f (x0)
f[x1 ,x0] = f [ x1 ] f [ x0 ]
x1 x0
x1 f (x1) f[x2 ,x1 ,x0] = f [ x2 , x1 ] f [ x1 , x0 ]
x2 x0
f[x2 ,x1] = f [ x2 ] f [ x1 ]
x2 x1 f[x3 ,x2 ,x1,x0]
Interpolate
x2 f (x2) f[x3 ,x2 ,x1] = f [ x3 , x2 ] f [ x2 , x1 ] f[x4, data
x3 x1
x3,x2,x1,x0] incrementally
f[x3 ,x2] = f [ x3 ] f [ x2 ] f[x4 ,x3 ,x2,x1]
x3 x2
x3 f (x3) f[x4 ,x3 ,x2] = f [ x4 , x3 ] f [ x3 , x2 ]
x4 x2
f [ x 4 ] f [ x3 ]
f [x4 ,x3] =
x 4 x3
x4 f (x4)
22
**CLASS ACTIVITY
Compute f(4) for the given data
x 3 5 2 6 1
4th order
2nd order
1st order 3rd order difference
i xi f(xi) f [xj, xi] f [xk, xj, xi] f [xl, xk, xj, xi] f [xn, xl, xk, xj, xi]
0 3 5.25 0
7.25
1 5 19.75 2.0
5.25 0.25
2 2 4 2.75 –0.125
8.0 0.50
3 6 36 1.75
6.25 f(4) =5.25+(4-3)(7.25) +(4-5)(4-3)(2) +(4-2)(4-5)(4-3)(0.25) = 10
4 1 4.75 23
CONCLUDING REMARKS
24
METHOD #2:
LAGRANGE INTERPOLATING
POLYNOMIALS
25
LAGRANGE INTERPOLATING POLYNOMIALS
if x x0 , f ( x0 ) y0 a0 ( x0 x1 )
if x x1 , f ( x1 ) y1 a1 ( x1 x0 )
26
LAGRANGE INTERPOLATING POLYNOMIALS
( x x1 ) ( x x0 )
Linear f1 x f ( x0 ) f ( x1 )
Interpolation: ( x0 x1 ) ( x1 x0 )
f ( x0 ) L0 ( x) f ( x1 ) L1 ( x)
( x x0 ) ( x x0 )
where L0 L1
( x0 x1 ) ( x1 x0 )
27
LAGRANGE INTERPOLATING POLYNOMIALS
General f x
n n (x x j ) n
model:
n
i 0
f ( xi )
j 0 ( xi x j )
f ( xi ) Li ( x)
i 0
j i
Linear
Interpolation:
28
CLASS ACTIVITY
Develop a first-order (linear) Lagrange interpolating polynomial
to evaluate f(x) = ln(2) that passes through the points (1,0) and
(4, 1.3863) . Find f (2). See example 18 in the Textbook .
x 1 4
Find f(2) = ?
y=ln x 0 1.3863
n n (x x j )
General f n x yi
model: i 0 j 0 ( xi x j )
j i
( x x1 ) ( x x0 )
Linear f1 x y0 y1
interpolation: ( x0 x1 ) ( x1 x0 )
29
SOLUTION
Pass through 2 points:
x0 = 1 ; y0 = 0
x1 = 4 ; y1 = 1.3863 Find f(2) = ?
( x x1 ) ( x x0 )
Linear model: f1 x y0 y1
( x0 x1 ) ( x1 x0 )
x4 x 1
f1 x (0) (1.3863)
1 4 4 1
simplify : f1 x 0.4621x 0.4621
30
Linear Lagrange Interpolation for f(x) = ln x
31
**LAGRANGE INTERPOLATING POLYNOMIALS
Quadratic
Interpolation:
Not so efficient
because need to
• The general form: re-compute the
polynomial terms!
n n (x x j )
f n x yi
i 0 j 0 ( xi x j )
j i
32
**CLASS ACTIVITY
Develop a Lagrange interpolating polynomial of second order
that passes through the points (1,0), (4, 1.3863) and
(6,1.7918). Find f(2)=ln(2). Example 18 of the Textbook .
n n (x x j )
General f n x yi
model: i 0 j 0 ( xi x j )
j i
Quadratic ( x x1 )( x x2 ) ( x x0 )( x x2 ) ( x x0 )( x x1 )
f 2 x y0 y1 y2
model: ( x0 x1 )( x0 x2 ) ( x1 x0 )( x1 x2 ) ( x2 x0 )( x2 x1 )
33
**SOLUTION
Develop a Lagrange interpolating polynomial of second order
that passes through y=ln(x) points (1,0), (4, 1.3863) and
(6,1.7918). Find f(2)=ln(2). Example 18 of the Textbook .
( x x1 )( x x2 ) ( x x0 )( x x2 ) ( x x0 )( x x1 )
Quadratic f 2 x y0 y1 y2
model: ( x0 x1 )( x0 x2 ) ( x1 x0 )( x1 x2 ) ( x2 x0 )( x2 x1 )
f 2 (2) 0.5658
1.7918
1.3863
0.2310 0.1792
versus true value, ln(2) = 0.6931 (4 1)( 4 6) (6 1)(6 4)
Error t = 18.4% 34
Quadratic Lagrange Interpolation for f(x) = ln x
35
COMPARISON
36
SUMMARY
37