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

Lec5 Numerical Model

Here are the steps to solve this problem: 1) Given data points: (0, 1), (2, 2.7183), (4, 7.3891) 2) Use quadratic interpolation formula: f(x) = b0 + b1(x - x0) + b2(x - x0)(x - x1) 3) Set x = x0 to find b0: b0 = f(x0) = 1 4) Set x = x1 to find b1: b1 = f[x1, x0] = (2.7183 - 1)/(2 - 0) = 0.8591 5) Set x =

Uploaded by

NoorLiana Mahmud
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)
73 views

Lec5 Numerical Model

Here are the steps to solve this problem: 1) Given data points: (0, 1), (2, 2.7183), (4, 7.3891) 2) Use quadratic interpolation formula: f(x) = b0 + b1(x - x0) + b2(x - x0)(x - x1) 3) Set x = x0 to find b0: b0 = f(x0) = 1 4) Set x = x1 to find b1: b1 = f[x1, x0] = (2.7183 - 1)/(2 - 0) = 0.8591 5) Set x =

Uploaded by

NoorLiana Mahmud
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/ 37

MDB3053 Numerical Methods

INTERPOLATION

Chapter 18 in Textbook

1
LESSON OUTCOMES

By the end of the lesson, students should be able


to
1. To perform interpolation to predict
unknown data based on available data
2. To analyze the accuracy of interpolated
results with different polynomials of order n

2
APPLICATION

Example: Spatial data reconstruction

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.

What is the y value


between x = 6 and 7?

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

• *Spline interpolation is an alternative technique for fitting


precise data points by fitting polynomial data in a piecewise
manner

5
INTERPOLATION

•For n+1 data points, there is one and only one polynomial
of order n that passes through all the points.

a) 1st-order polynomial b) 2nd-order (quadratic) c) 3rd-order (cubic)


connects 2 points to …… 3 points to …… 4 points to
solve 2 unknowns ..….. 3 unknowns ……4 unknowns

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

•Slight variation for Newton’s Divided-Difference Interpolation

y a 0  a1 x y a 0 a1 x  a2 x 2 y a 0 a1 x  a2 x 2  a3 x3

y b0 b1 x  x 0  y b0 b1 x  x 0   b2 x  x o x  x1)


7
METHOD #1:

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)

(2) into (1) f ( x)  f ( x ) 


f x1   f x0 
( x  x0 )  f ( x 0 )  f [ x1 , x0 ]( x  x0 )
x1  x0
1 0

10
CLASS ACTIVITY

Develop a linear interpolation formula for function f(x) = e0.5x


using values at x0 = 0 and x1=2. Evaluate f(1) and find error t .
x 0 2 Ans: t = 12.76%
Find f(1) = ?
y 1 2.7183

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

f x1   f x0  2.7183  1


b1    0.8592
x1  x0 20

Rewrite: f (x) = 1 + 0.8592(x  x0) = 1 + 0.8592(x – 0)

when x = 1, f (1) = 1 + 0.8592(1-0) = 1.8592 versus true value = 1.6487

True percent error: t = 12.8%


12
Linear Newton’s Interpolation for f(x) = e0.5x

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:

f (x) = b0 + b1(x  x0) + b2(x  x0 )(x  x1)

Next, find the value for coefficients: bo , b1 and b2 by


substituting 3 known data points.

14
To find b0, b1 and b2

f (x) = b0 + b1(x  x0) + b2(x  x0 )(x  x1)

To find Set

f (x0 )= b0 + b1(x0  x0) + b2(x0  x0 )(x0  x1)

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)

where: b0 = f(x0) zero order

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

Quadratic model: f (x) = b0 + b1(x  x0) + b2(x  x0 )(x  x1)


where
f [ x2 , x1 ]  f [ x1 , x0 ]
b0 = f2(x0) b1  f [ x1 , x0 ] b2   f [ x2 , x1 , x0 ]
x2  x0

Ans: b0 = 1, b1 = 0.8591 , b2 = 0.3691 17


t = 9.62%
SOLUTION
Pass through 3 points:
x0 = 0 ; f(x0) = e0.5(0) = 1
x1 = 2 ; f(x1) = e0.5(2) = 2.7183
x2 = 4 ; f(x2) = e0.5(4) = 7.3891 Find f (1) = ?

Quadratic model: f (x) = b0 + b1(x  x0) + b2(x  x0 )(x  x1)

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 20
2 1 1 0

x2  x0
(7.3891  2.7183)
 0.8592
( 4  2)
  0.3691
( 4  0)

Rewrite: f (x) = 1+ 0.8592(x  0)  0.3691(x  0)(x  2)


= 1 + 0.8592x  0. 3691 x(x  2)
f (1) = 1.4901 versus true value= 1.6487 t = 9.62% 18
Quadratic Newton’s Interpolation for f(x) = e0.5x

19
NEWTON DIVIDED DIFFERENCE –
General form of nth order polynomial

• For nth order Newton’s divided-difference interpolating


polynomial for n+1 data points
f n x   b0  b1 x  x0   ...  bn  x  x0  x  x1 ...x  xn 1 
where
b0  f  x0 
b0,b1, b2…, bn
b1  f x1 , x0  are evaluated
b2  f x2 , x1 , x0  in a recursive
formula

bn  f [ xn , xn 1 , xn  2 ,..., x1 , x0 ]

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

nth order difference


f [ xn , xn 1 ,.., x2 , x1 ]  f [ xn 1 , xn  2 ,..., x1 , x0 ]
f [ xn , xn 1 ,..., x2 , x1 , x0 ] 
xn  x0

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

y 5.25 19.75 4 36 4.75

Calculate f(4) using Newton’s interpolating polynomials of order 1 through 3.

Solution: construct divided-difference table


f(x) = f[x0] + (x–x0)f[x1,x0] + (x–x1)(x–x0)f[x2,x1,x0] + (x–x2)(x–x1)(x–x0)f[x3,x2,x1,x0]

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

Newton’s Divided Difference Interpolation


• need to compute new “divided-difference” terms when new data
points are interpolated for higher order function
•it is an efficient scheme when new data point is added because prior
terms can be re-used and it interpolates data incrementally
•Construct table to make use of recursive terms for higher order
interpolation

24
METHOD #2:

LAGRANGE INTERPOLATING
POLYNOMIALS

25
LAGRANGE INTERPOLATING POLYNOMIALS

• If 2 data points are available, we can use a linear equation to


fit the data in this form:
Linear Interpolation: f1 x   a0  a1 x

• Or we can express it in a different form, known as Lagrange


polynomial of linear order as:
f x   a0 ( x  x1 )  a1 ( x  x0 )

• To find constants a0, and a1 , we compare the terms at yi for i=0,1

if x  x0 , f ( x0 )  y0  a0 ( x0  x1 )
if x  x1 , f ( x1 )  y1  a1 ( x1  x0 )
26
LAGRANGE INTERPOLATING POLYNOMIALS

• Rearrange the terms so that a0 , a1:


f ( x0 ) f ( x1 )
a0  a1 
( x0  x1 ) ( x1  x0 )

• By substituting a0 and a1 into the Lagrange polynomial:

( 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

• which can be expressed in a compact form as:

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

where  denotes the ' product' of

• For example, the linear version (n =1) is in a form of:

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 )
x4 x 1
 f1  x   (0)  (1.3863)
1 4 4 1
simplify : f1  x   0.4621x  0.4621

at x  2 f1 (2)  0.4621(2)  0.4621  0.4621

versus true value, ln(2) = 0.6931


True percent Error t = 33.3%

30
Linear Lagrange Interpolation for f(x) = ln x

31
**LAGRANGE INTERPOLATING POLYNOMIALS

• For example, the second order (n =2) is in a form of:

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

Pass through 3 points:


x0 = 1 ; y0 = 0
x1 = 4 ; y1 = 1.3863
x2 = 6 ; y2 = 1.7918 Find f(2) = ?

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 .

Pass through 3 points (y = ln x) :


x0 = 1 ; y0 = 0
x1 = 4 ; y1 = 1.3863
x2 = 6 ; y2 = 1.7918 Find f(2) = ?

( 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 x   0  0.231( x  1)( x  6)  0.1792( x  1)( x  4)

 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

Newton’s Divided Lagrange Interpolation


Difference Interpolation
• not so efficient when new
• more efficient when new data point is added because it
data point is added because requires computing the
prior terms can be re-used and polynomial again
it interpolates data
• use as a theoretical tool for
incrementally
proving theorem if using same
•Construct table to make use set of data point
of recursive terms for higher
order interpolation

36
SUMMARY

• 2 numerical techniques to perform INTERPOLATION:


• Newton’s Divided Difference (preferred)
• Lagrange Interpolation

 We have covered Chapter 18 in textbook

37

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy