Lecture 12
Lecture 12
Ata Babakhani
uOttawa.ca
2
Agenda
• wooclap
• Assignment Review
• Polynomial Interpolation
-Newton Interpolation
uOttawa.ca
3
wooclap
uOttawa.ca
4
wooclap
uOttawa.ca
5
Assignment
uOttawa.ca
6
Assignment
uOttawa.ca
7
Assignment
uOttawa.ca
8
uOttawa.ca
9
uOttawa.ca
10
𝐶 (𝑡) ?
t0 t1 t2 t3 t tn-1 tn
How can we find C(t) function using the collected samples at different time intervals?
uOttawa.ca
11
uOttawa.ca
12
Interpolating Function
uOttawa.ca
13
Polynomial Interpolation
uOttawa.ca
14
Polynomial Interpolation
n+1 data points generate a polynomial of order n
i 0 1
xi x0 x1
f(xi) f(x0) f(x1)
Example:
i 0 1
xi 1 6 f(2)=?
f(xi) 0 1.7917595
uOttawa.ca
15
Polynomial Interpolation
n+1 data points generate a polynomial of order n
i 0 1 2
xi x0 x1 x2
f(xi) f(x0) f(x1) f(x2)
uOttawa.ca
16
Polynomial Interpolation
i 0 1 2 …. n-1 n
xi x0 x1 x2 …. xn-1 xn
f(xi) f(x0) f(x1) f(x2) …. f(xn-1) f(xn)
An nth-order polynomial that passes through the n+1 points can be written as:
Example:
𝑓 𝑥 = 𝑎0 i 0 1
+ 𝑎1 𝑥 − 𝑥0 x 1 6 i
f(x ) 0 1.7917595
+ 𝑎2 𝑥 − 𝑥0 (𝑥 − 𝑥1 ) i
.
.
+𝑎𝑛−1 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2 ⋯ 𝑥 − 𝑥𝑛−2
+𝑎𝑛 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2 ⋯ 𝑥 − 𝑥𝑛−1
The target is to find the coefficients a0 , a1 , . . ., an
uOttawa.ca
17
Interpolating Function
uOttawa.ca
18
Newton Interpolation
𝑓 𝑥 = 𝑎0
+ 𝑎1 𝑥 − 𝑥0
+ 𝑎2 𝑥 − 𝑥0 (𝑥 − 𝑥1 )
.
.
+𝑎𝑛−1 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2 ⋯ 𝑥 − 𝑥𝑛−2
+𝑎𝑛 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2 ⋯ 𝑥 − 𝑥𝑛−1
Based on the Newton method, the nth coefficient can be calculated as below:
uOttawa.ca
19
Newton Interpolation
𝑎0 = 𝑓 𝑥0 = 𝑓(𝑥0 )
𝑓(𝑥1 ) − 𝑓(𝑥0 )
𝑎1 = 𝑓 𝑥1 , 𝑥0 = The first-order divided difference
𝑥1 − 𝑥0
𝑓 𝑥2 , 𝑥1 − 𝑓 𝑥1 , 𝑥0
𝑎2 = 𝑓 𝑥2 , 𝑥1 , 𝑥0 = The second-order divided difference
𝑥2 − 𝑥0
𝑓 𝑥3 , 𝑥2 , 𝑥1 − 𝑓 𝑥2 , 𝑥1 , 𝑥0
𝑎3 = 𝑓 𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 =
𝑥3 − 𝑥0
uOttawa.ca
20
Newton Interpolation
The Newton method coefficients using four data points:
xi f (xi) f [xn , xn-1] f [xn , xn-1 , xn-2] f [xn , xn-1 , xn-2 , xn-3]
x0 f(x0)
f [x1 , x0]
= f (x1)- f(x0)
x1-x0
f [x2 , x1 , x0]
x1 f(x1) = f [x2, x1]- f [x1, x0]
x2-x0 𝑓(𝑥)
f [x2 , x1] f [x3, x2 , x1 , x0]
= f(x2)- f(x1) = f [x3, x2, x1]- f [x2, x1, x0]
x2-x1 x3-x0
f [x3 , x2 , x1]
x2 f(x2) = f[x3, x2]- f [x2, x1]
x3-x1
f [x3 , x2] x0 x1 x2 x3
= f(x3)- f(x2)
x3-x2
x3 f(x3)
Newton Interpolation-Example
Example 1:
Find f(2) based on the given points:
i 0 1
a) xi 1 6
Two points = First-order polynomial
f(xi) 0 1.7917595
𝑓(𝑥1 ) − 𝑓(𝑥0 )
𝑓 𝑥1 , 𝑥0 =
𝑥1 − 𝑥0
uOttawa.ca
22
Example 2:
Find f(2) based on the given points:
i 0 1
b) xi 1 4 Two points = First-order polynomial
f(xi) 0 1.3862944
𝑓(𝑥1 ) − 𝑓(𝑥0 )
𝑓 𝑥1 , 𝑥0 =
𝑥1 − 𝑥0
uOttawa.ca
23
i 0 1
(a) xi 1 6 f(2)=0.3583519
f(xi) 0 1.7917595
i 0 1
(b) xi 1 4 f(2)=0.4620981
f(xi) 0 1.3862944
ln(2)=0.6931472
In general, the smaller the interval between the data points,
the better the approximation
uOttawa.ca
24
Example 3:
Find f(2) based on the given points:
i 0 1 2
c) xi 1 4 6 Three points = Second-order polynomial
f(xi) 0 1.3862944 1.7917595
𝑓(𝑥1 ) − 𝑓(𝑥0 )
𝑓 𝑥1 , 𝑥0 =
𝑥1 − 𝑥0
𝑓 𝑥2 , 𝑥1 − 𝑓 𝑥1 , 𝑥0
𝑓 𝑥2 , 𝑥1 , 𝑥0 =
𝑥2 − 𝑥0
i x f(x) f[xn,xn-1] f[xn,xn-1,xn-2]
0 1 0
0.46209812
1 4 1.3862944
0.202732554
-0.051873113 f(2)=0.5658444
2 6 1.7917595
uOttawa.ca
26
i 0 1
(a) xi 1 6 f(2)=0.3583519
f(xi) 0 1.7917595
i 0 1
(b) xi 1 4 f(2)=0.4620981
f(xi) 0 1.3862944
ln(2)=0.6931472
i 0 1 2
(c) xi 1 4 6
f(2)=0.5658444
f(xi) 0 1.3862944 1.7917595
𝑓(𝑥1 ) − 𝑓(𝑥0 ) 𝑓 𝑥2 , 𝑥1 − 𝑓 𝑥1 , 𝑥0
𝑓 𝑥1 , 𝑥0 = 𝑓 𝑥2 , 𝑥1 , 𝑥0 =
𝑥1 − 𝑥0 𝑥2 − 𝑥0
uOttawa.ca
28
Non-Sorted Sorted
i x f(x) f[xn,xn-1] f[xn,xn-1,xn-2] i x f(x) f[xn,xn-1] f[xn,xn-1,xn-2]
0 1 0 0 4 1.3862944
0.46209812 0.202732554
1 4 1.3862944 -0.051873113 1 6 1.7917595 -0.051873113
0.202732554 0.358351894
2 6 1.7917595 2 1 0
f(4.5)=1.778 f(4.5)=1.394
εt =18.19% f(4.5)=ln(4.5)=1.504 εt =7.34%