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

Interpolation

Uploaded by

Aslı
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)
9 views

Interpolation

Uploaded by

Aslı
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/ 19

NUMERICAL

INTERPOLATION

Prof. Dr. Seher KUMCUOĞLU


Doç. Dr. Onur ÖZDİKİCİERLER

12/13/2024 Numerical Analysis 2024-2025 1


INTERPOLATION
In engineering calculations, you will frequently have
occasion to estimate intermediate values between
precise data points. The most common method used
for this purpose is polynomial interpolation.
General formula for an nth-order polynomial is:

𝑓 𝑥 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + 𝑎3 𝑥 3 + ⋯ ⋯ ⋯ + 𝑎𝑛 𝑥 𝑛

For n+1 data points, there is one and only one polynomial of order n that passes
through all the points. For example, there is only one straight line (that is, a first-order
polynomial) that connects two points. Similarly, only one parabola connects
a set of three points.

(a) (b) (c)


(a) (c)
first-order (linear) third-order (cubic)
connecting two connecting four
points points

(b) Second order (quadratic or parabolic) connecting three points

12/13/2024 Numerical Analysis 2024-2025 2


INTERPOLATION
Polynomial interpolation consists of determining the unique nth-order
polynomial that fits n+1 data points. This polynomial then provides a
formula to compute intermediate values.

▪ Given the following n+1 data


(x1, y1), (x2, y2), (x3, y3), ………., (xn+1, yn+1)
▪ the unique nth-order polynomial that passes through them
𝑝 𝑥 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + 𝑎3 𝑥 3 + ⋯ ⋯ ⋯ + 𝑎𝑛 𝑥 𝑛
▪ The question is to find the coefficients: a0, a1, a2, ……,an

Polynomial interpolation:
1. Newton’s divided-difference interpolating polynomial
2. Lagrange interpolating polynomial

12/13/2024 Numerical Analysis 2024-2025 3


NEWTON’S DIVIDED-DIFFERENCE
INTERPOLATING POLYNOMIALS
Linear interpolation: • Given (x0, y0) and (x1, y1))
• A straight line passes from these
two points
a0+a1x
• Using similar triangles
y1=f(x1) 𝑓 𝑥 − 𝑓 𝑥0 𝑓 𝑥1 − 𝑓 𝑥0
=
𝑥 − 𝑥0 𝑥1 − 𝑥0
?
𝑓 𝑥1 − 𝑓 𝑥0
y0=f(x0) 𝑓 𝑥 = 𝑓 𝑥0 + 𝑥 − 𝑥0
𝑥1 − 𝑥0

x 𝑓1 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0
x0 x x1

Linear interpolation formula

12/13/2024 Numerical Analysis 2024-2025 4


Quadratic interpolation:

If three data points are available, this can be accomplished with a


second-order polynomial (also called a quadratic polynomial or a
parabola).

a0+a1x+a2x2

y2=f(x2)
• Given (x0, y0), (x1, y1) and (x2, y2)
y1=f(x1)
• A parabola passes from these
three points

y0=f(x0)

x
x0 x1 x2 Quadratic interpolation formula

𝑓2 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 𝑥 − 𝑥0 𝑥 − 𝑥1

12/13/2024 Numerical Analysis 2024-2025 5


Quadratic interpolation:
𝑓2 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 𝑥 − 𝑥0 × 𝑥 − 𝑥1

𝑓 𝑥 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + 𝑎3 𝑥 3 + ⋯ ⋯ ⋯ + 𝑎𝑛 𝑥 𝑛

Note that although this equation might seem to differ from the general
polynomial the two equations are equivalent.

𝑓2 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑏1 𝑥0 + 𝑏2 𝑥 2 + 𝑏2 𝑥0 𝑥1 − 𝑏2 𝑥𝑥0 − 𝑏2 𝑥𝑥1

How to find b0, b1 and b2 in terms of given quantities?

𝑎0 = 𝑏0 − 𝑏1 𝑥0 + 𝑏2 𝑥0 𝑥1

𝑎1 = 𝑏1 − 𝑏2 𝑥0 − 𝑏2 𝑥1

𝑎2 = 𝑏2

12/13/2024 Numerical Analysis 2024-2025 6


Quadratic interpolation:

𝑓2 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 𝑥 − 𝑥0 𝑥 − 𝑥1

How to find b0, b1 and b2 in terms of given quantities?

• at x = x0 ; f2(x) = f2(x0) = b0 b0= f(x0)

𝑓 𝑥1 − 𝑓 𝑥0
• at x = x1 ; f2 (x) = f2 (x1) = b0 + b1x1 𝑏1 =
𝑥1 − 𝑥0

• at x = x2 ; f2 (x) = f2 (x2) = b0 + b1 (x2-x0) + b2 (x2-x0) (x2-x1)

𝑓 𝑥2 − 𝑓 𝑥1 𝑓 𝑥1 − 𝑓 𝑥0

𝑥2 − 𝑥1 𝑥1 − 𝑥0
𝑏2 =
𝑥2 − 𝑥0

12/13/2024 Numerical Analysis 2024-2025 7


General Form of Newton’s Interpolating
Polynomials
The preceding analysis can be generalized to fit an nth-order polynomial to n +1
data points. The nth order polynomial is:
𝑓𝑛 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 𝑥 − 𝑥0 𝑥 − 𝑥1 + ⋯ ⋯ ⋯ + 𝑏𝑛 𝑥 − 𝑥0 𝑥 − 𝑥1 ⋯ ⋯ 𝑥 − 𝑥𝑛−1

b0 = f(x0) where the bracketed function evaluations are


finite divided differences.
b1 = f [x1, x0 ]
• The 1st finite divided difference:
b2 = f [x2, x1, x0 ] 𝑓 𝑥𝑖 − 𝑓 𝑥𝑗
𝑓 𝑥𝑖 , 𝑥𝑗 =
𝑥𝑖 − 𝑥𝑗
bn = f [xn, xn-1, ……., x1, x0 ]
𝑓 𝑥𝑖 , 𝑥𝑗 − 𝑓 𝑥𝑗 , 𝑥𝑘
• The 2nd finite divided difference: 𝑓 𝑥𝑖 , 𝑥𝑗 , 𝑥𝑘 =
𝑥𝑖 − 𝑥𝑘
• the nth finite divided difference:
𝑓 𝑥𝑛 , 𝑥𝑛−1 ⋯ , 𝑥1 − 𝑓 𝑥𝑛−1 , ⋯ , 𝑥0
𝑓 𝑥𝑛 , 𝑥𝑛−1 , ⋯ , 𝑥1 , 𝑥0 =
𝑥𝑛 − 𝑥0

12/13/2024 Numerical Analysis 2024-2025 8


General Form of Newton’s Interpolating
Polynomials
Therefore a divided difference table is constructed to find the desired value of the
function

xi f(xi) First Second Third


x0 f(x0) f [x1, x0 ] f [x2, x1, x0 ] f [x3, x2, x1, x0]
x1 f(x1) f [x2, x1 ] f [x3, x2, x1 ]
x2 f(x2) f [x3, x2 ]

Newton’s divided-difference interpolating polynomial:

𝑓𝑛 𝑥
= 𝑓 𝑥0 + 𝑥 − 𝑥0 𝑓 𝑥1 , 𝑥0 + 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑓 𝑥2 , 𝑥1 , 𝑥0 + ⋯ ⋯ ⋯
+ 𝑥 − 𝑥0 𝑥 − 𝑥1 ⋯ ⋯ 𝑥 − 𝑥𝑛−1 𝑓 𝑥𝑛−1 , 𝑥𝑛 , ⋯ , 𝑥0

The near row that has smaller sequence number row is called as base raw.

12/13/2024 Numerical Analysis 2024-2025 9


Example: Consider the data given below and calculate f(x) for x=3.5.
x: 0 1 3 4 6 7
f(x) -5 1 25 55 181 289

Solution:
xi f(xi) f1 [ ] f2 [ ] f3 [ ] f4 [ ]
0 -5 6 2 1 0
1 1 12 6 1 0
3 25 30 11 1 base row
4 55 63 15
6 181 108
7 289
𝑓𝑛 𝑥
= 𝑓 𝑥0 + 𝑥 − 𝑥0 𝑓 𝑥1 , 𝑥0 + 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑓 𝑥2 , 𝑥1 , 𝑥0 + ⋯ ⋯ ⋯
+ 𝑥 − 𝑥0 𝑥 − 𝑥1 ⋯ ⋯ 𝑥 − 𝑥𝑛−1 𝑓 𝑥𝑛−1 , 𝑥𝑛 , ⋯ , 𝑥0
𝑓 3.5 = 𝑓 3 + 𝑥 − 3 𝑓1 [ ] + 𝑥 − 3 𝑥 − 4 𝑓2 [ ] + 𝑥 − 3 𝑥 − 4 𝑥 − 6 𝑓3 [ ]

𝑓 3.5 = 25 + 3.5 − 3 × 30 + 3.5 − 3 3.5 − 4 × 11 + 3.5 − 3 3.5 − 4 3.5 − 6 × 1 = 37.875

12/13/2024 Numerical Analysis 2024-2025


10
Example: Consider the data given below and calculate f(x) for x=4.
x: 1 2 5 7 8 11
f(x) 4 10 40 70 88 154

Solution:
x f(xi) f1 [ ] f2 [ ] f3 [ ]
1 4 6 1 0
2 10 10 1 0 base row
5 40 15 1 0
7 70 18 1
8 88 22
11 154

𝑓 4 = 𝑓 2 + 𝑥 − 2 𝑓1 [ ] + 𝑥 − 2 𝑥 − 5 𝑓2 [ ]

𝑓 4 = 10 + 4 − 2 × 10 + 4 − 2 4 − 5 × 1 → 𝑓 4 = 28

12/13/2024 Numerical Analysis 2024-2025


11
GREGORY NEWTON FORWARD DIFFERENCE
METHOD
If the difference between independent variables are regular such as xi= x0 + iΔx
(i=0,1,2……n) , a simple form of the divided difference formula is used (Δx =1 and
the x = 0 for base row) and the mathematical model is called as forward difference
method and it is applied for the points near the top of the data table.

These simple differencences: Δfi

• The 1st order forward difference: Δfi = fi+1-fi

From the definition of first divided difference:

𝑓 𝑥1 − 𝑓 𝑥0 𝑓 𝑥1 − 𝑓 𝑥0
𝑓 𝑥1 , 𝑥0 = = → ∆𝑓0 = ∆𝑥. 𝑓 𝑥1 , 𝑥0
𝑥1 − 𝑥0 ∆𝑥
Similarly we can get ∆𝑓1 = ∆𝑥. 𝑓 𝑥2 , 𝑥1

• The 2nd order forward difference: Δ2fi = Δfi+1-Δfi


𝑓 𝑥2 , 𝑥1 − 𝑓 𝑥1 , 𝑥0
∆2 𝑓0 = ∆𝑓1 − ∆𝑓0 = ∆𝑥 𝑓 𝑥2 , 𝑥1 − 𝑓 𝑥1 , 𝑥0 = 2∆𝑥 2
𝑥2 − 𝑥0

12/13/2024 Numerical Analysis 2024-2025 12


GREGORY NEWTON FORWARD DIFFERENCE
METHOD
• The kthorder forward difference: Δkfi = Δk-1fi+1-Δk-1fi

∆𝑘 𝑓𝑖 = 𝑘! ∆𝑥 𝑘 𝑓 𝑥𝑖+𝑘 , ⋯ , 𝑥𝑖

∆𝑘 𝑓𝑖
𝑓 𝑥𝑖+𝑘 , ⋯ , 𝑥𝑖 = 𝑘
𝑘! ∆𝑥

i=0;
𝑛 𝑘−1
∆𝑘 𝑓0 ∆𝑘 𝑓0
𝑓 𝑥𝑘 , ⋯ , 𝑥0 , = 𝑓𝑛 𝑥 = ෍ ෑ 𝑥 − 𝑥𝑖
𝑘! ∆𝑥 𝑘 𝑘! ∆𝑥 𝑘
𝑘=0 𝑖=0

∆2 𝑓 𝑥 − 𝑥𝐵 𝑥 − 𝑥𝐵+1 ∆3 𝑓 𝑥 − 𝑥𝐵 𝑥 − 𝑥𝐵+1 𝑥 − 𝑥𝐵+2


𝑓 𝑥 = 𝑓 𝑥𝐵 + 𝑥 − 𝑥𝐵 ∆𝑓 + + +⋯⋯⋯
2! 3!

12/13/2024 Numerical Analysis 2024-2025 13


Example: Consider the data given below and calculate f(x) for x=0.25.
x: 0.1 0.2 0.3 0.4 0.5 0.6
f(x) 2.03 4.12 6.27 8.48 10.75 13.08

x xn f(xi) Δf Δ2f Δ3f Δ4f base row


0.1 -1 2.03 2.09 0.06 0 0 The new value of x for base row
0.2 0 4.12 2.15 0.06 0 0 should be zero and difference
between consequent values of x
0.3 1 6.27 2.21 0.06 0 should be equal.
0.4 2 8.48 2.27 0.06
Second row is base row and the
0.5 3 10.75 2.33 formula of x = (x - xB )/ Δx is applied
to make xB = 0
0.6 4 13.08

f(0.25)=? 0.25 − 0.2


𝑓 = 𝑓 0.5 =? → 𝑛𝑒𝑤 𝑥 𝑣𝑎𝑙𝑢𝑒
0.1
∆2 𝑓 𝑥 − 𝑥𝐵 𝑥 − 𝑥𝐵+1
𝑓 𝑥 = 𝑓 𝑥𝐵 + 𝑥 − 𝑥𝐵 ∆𝑓 +
2!

(0.5 − 0) × 2.15 (0.5 − 0) × 0.5 − 1 × 0.06


𝑓 0.5 = 4.12 + + → 𝑓 0.25 = 5.1875
1! 2!

12/13/2024 Numerical Analysis 2024-2025 14


Example: Consider the data given below and calculate f(0.23) using with
forward divided differense methodfor x=0.23.
x: 0.0 0.2 0.4 0.6 0.8
f(x) 1 0.916 0.836 0.74 0.624

x xn f(xi) Δf Δ2f Δ3f Δ4f


base row
0 -1 1 -0.084 0.004 -0.02 0.016
0.2 0 0.916 -0.08 -0.016 -0.04
0.4 1 0.836 -0.0916 -0.02
0.6 2 0.74 -0.116
0.8 3 0.624

f(0.23)=? 0.23 − 0.2


𝑓 = 𝑓 0.15 =? → 𝑛𝑒𝑤 𝑥 𝑣𝑎𝑙𝑢𝑒
0.2
∆2 𝑓 𝑥 − 𝑥𝐵 𝑥 − 𝑥𝐵+1 ∆3 𝑓 𝑥 − 𝑥𝐵 𝑥 − 𝑥𝐵+1 𝑥 − 𝑥𝐵+2
𝑓 𝑥 = 𝑓 𝑥𝐵 + 𝑥 − 𝑥𝐵 ∆𝑓 + +
2! 3!
(0.15 − 0) −0.08 (0.15 − 0) 0.15 − 1 −0.016 (0.15 − 0)(0.15 − 1)(0.15 − 2) −0.04
𝑓 0.15 = 0.916 + + +
1! 2! 3!
= 0.9049

12/13/2024 Numerical Analysis 2024-2025 15


LAGRANGE INTERPOLATION
Luis Lagrange is a mathematician an he lives in Paris along french
revolution. (1736-1813) He also prove that a polynom has n roots if
degree of it is n.
The Lagrange interpolating polynomial is simply a reformulation
of the Newton polynomial that avoids the computation of divided
differences. It can be represented as:
𝑛 𝑛
𝑓𝑛 𝑥 = ෍ 𝐿𝑖 𝑥 𝑓 𝑥𝑖 𝑥 − 𝑥𝑗
where 𝐿𝑖 𝑥 = ෑ
𝑖=0 𝑥𝑖 − 𝑥𝑗
𝑗=0
𝑗≠𝑖

• For n=1 (linear): 𝑓1 𝑥 =


𝑥 − 𝑥1
𝑥0 − 𝑥1
𝑓 𝑥0 +
𝑥 − 𝑥0
𝑥1 − 𝑥0
𝑓 𝑥1

• For n=2 : 𝑓2 𝑥 =
𝑥 − 𝑥1 𝑥 − 𝑥2
𝑥0 − 𝑥1 𝑥0 − 𝑥2
𝑓 𝑥0 +
𝑥 − 𝑥0 𝑥 − 𝑥2
𝑥1 − 𝑥0 𝑥1 − 𝑥2
𝑓 𝑥1 +
𝑥 − 𝑥0 𝑥 − 𝑥1
𝑥2 − 𝑥0 𝑥2 − 𝑥1
𝑓 𝑥2

• To generalize, nth order polynomial is the summation of (n+1) nth order polynomials

12/13/2024 Numerical Analysis 2024-2025 16


Example: Use the following data and calculate f(3.5).
x: 0 1 3 4 6 7
f(x) -5 1 25 55 181 289

Solution:
𝑛
𝑛 𝑥 − 𝑥𝑗
𝐿𝑖 𝑥 = ෑ
𝑓𝑛 𝑥 = ෍ 𝐿𝑖 𝑥 𝑓 𝑥𝑖 𝑥𝑖 − 𝑥𝑗
𝑗=0
𝑖=0 𝑗≠𝑖

𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥3 𝑥 − 𝑥4 𝑥 − 𝑥5
𝑓 𝑥0 𝐿0 𝑥 = 𝑓 𝑥0
𝑥0 − 𝑥1 𝑥0 − 𝑥2 𝑥0 − 𝑥3 𝑥0 − 𝑥4 𝑥0 − 𝑥5

3.5 − 1 3.5 − 3 3.5 − 4 3.5 − 6 3.5 − 7


𝑓 𝑥0 𝐿0 𝑥 = −5 = −0.054
0−1 0−3 0−4 0−6 0−7

𝑥 − 𝑥0 𝑥 − 𝑥2 𝑥 − 𝑥3 𝑥 − 𝑥4 𝑥 − 𝑥5
𝑓 𝑥1 𝐿1 𝑥 = 𝑓 𝑥1
𝑥1 − 𝑥0 𝑥1 − 𝑥2 𝑥1 − 𝑥3 𝑥1 − 𝑥4 𝑥1 − 𝑥5

3.5 − 0 3.5 − 3 3.5 − 4 3.5 − 6 3.5 − 7


𝑓 𝑥1 𝐿1 𝑥 = 1 = −0.043
1−0 1−3 1−4 1−6 1−7

12/13/2024 Numerical Analysis 2024-2025


17
Example: Use the following data and calculate f(3.5).
x: 0 1 3 4 6 7
f(x) -5 1 25 55 181 289

Solution:
𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥3 𝑥 − 𝑥4 𝑥 − 𝑥5
𝑓 𝑥2 𝐿2 𝑥 = 𝑓 𝑥2
𝑥2 − 𝑥0 𝑥2 − 𝑥1 𝑥2 − 𝑥3 𝑥2 − 𝑥4 𝑥2 − 𝑥5

3.5 − 0 3.5 − 1 3.5 − 4 3.5 − 6 3.5 − 7


𝑓 𝑥2 𝐿2 𝑥 = 25 = 13.292
3−0 3−1 3−4 3−6 3−7

𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥4 𝑥 − 𝑥5
𝑓 𝑥3 𝐿3 𝑥 = 𝑓 𝑥3
𝑥3 − 𝑥0 𝑥3 − 𝑥1 𝑥3 − 𝑥2 𝑥3 − 𝑥4 𝑥3 − 𝑥5

3.5 − 0 3.5 − 1 3.5 − 3 3.5 − 6 3.5 − 7


𝑓 𝑥3 𝐿3 𝑥 = 55 = 29.426
4−0 4−1 4−3 4−6 4−7

𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥3 𝑥 − 𝑥5
𝑓 𝑥4 𝐿4 𝑥 = 𝑓 𝑥4
𝑥4 − 𝑥0 𝑥4 − 𝑥1 𝑥4 − 𝑥2 𝑥4 − 𝑥3 𝑥4 − 𝑥5

3.5 − 0 3.5 − 1 3.5 − 3 3.5 − 4 3.5 − 7


𝑓 𝑥4 𝐿4 𝑥 = 181 = −7,699
6−0 6−1 6−3 6−4 6−7

12/13/2024 Numerical Analysis 2024-2025


18
Example: Use the following data and calculate f(3.5).
x: 0 1 3 4 6 7
f(x) -5 1 25 55 181 289

Solution:

𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 − 𝑥3 𝑥 − 𝑥4
𝑓 𝑥5 𝐿5 𝑥 = 𝑓 𝑥5
𝑥5 − 𝑥0 𝑥5 − 𝑥1 𝑥5 − 𝑥2 𝑥5 − 𝑥3 𝑥5 − 𝑥4

3.5 − 0 3.5 − 1 3.5 − 3 3.5 − 4 3.5 − 6


𝑓 𝑥5 𝐿5 𝑥 = 289 = 3.186
7−0 7−1 7−3 7−4 7−6

𝑓 3.5 = −0.054 − 0.043 + 13.292 + 29.426 − 7.699 + 3.136 = 38.058

12/13/2024 Numerical Analysis 2024-2025


19

You might also like