Part (13) - Interpolation 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Numerical Analysis 0905201

Chapter 18

Interpolation
Eng. Mohammad Al Nairat & Eng. Mohammad Musleh
1
Introduction
 Recall that the general formula for an nth-order polynomial is

 For (𝑛 + 1) data points, there is one and only one polynomial of order 𝑛 that passes through all the
points.
Introduction
 Many times, data is given only at discrete points
such as (x0, y0), (x1, y1), ......, (xn-1,
yn-1), (xn, yn).
So, how then does one find the value of y at any
other value of x ?

 Well, a continuous function f (x) may be used to


represent the n +1 data values with f (x) passing
through the n +1 points.

 Then one can find the value of y at any other value


of x . This is called interpolation.

 If x falls outside the range of x for which the data


is given, it is no longer interpolation but instead is
called extrapolation.
Interpolation Types

Polynomial Interpolation: A unique nth order polynomial passes through n points.


- Direct method
- Lagrange Interpolating Polynomials
- Newton’s Divided Difference Interpolating Polynomials

Spline Interpolation: Pass different curves through different subsets of the data
points.
Polynomial interpolation

A polynomial is a common choice for an interpolating function.

Polynomial interpolation involves finding a polynomial of order n that passes


through the n +1 points.
The methods of interpolation are:

a) Spline Method of interpolation

b) The direct method.

c) Lagrangian interpolation method.

d) Newton’s divided difference polynomial method


a) Spline Interpolation Method
 For high number of data points ( typically 𝑛 > 6 𝑜𝑟 7 ), high order polynomials are
necessary, but sometimes they suffer from oscillatory behavior.

 Instead of using a single high order polynomial that passes through all data points,
we can use different lower order polynomials between each data pair.

 These lower order polynomials that pass through only two points are called splines
a) Spline Interpolation Method

Linear Spline Interpolation:

Given a set of ordered data points, each two points can be connected using a straight
line (two points are required).
a) Spline Interpolation Method
Example 1
Consider the following data to find 𝑓(50) using the linear spline interpolation.

𝑓 𝑥1 − 𝑓 𝑥0
𝑓 𝑥 = 𝑓 𝑥0 + . 𝑥 − 𝑥0 x y
𝑥1 − 𝑥0
40 2.5
𝑓 75 − 𝑓 40 75 11.5
𝑓 𝑥 = 𝑓 40 + . 𝑥 − 40
75 − 40

11.5 − 2.5
𝑓 𝑥 = 2.5 + . (𝑥 − 40)
75 − 40
11.5 − 2.5
𝑓 50 = 2.5 + . 50 − 40 = 5.071
75 − 40
Example 2
Consider the table given in the figure to calculate the saturated pressure at a
temperature T=107 ℃ using the linear spline interpolation.
𝑥0 = 105 and 𝑥1 = 110 ,choosing 100 and 110 will be less accurate.

𝑓 𝑥2 − 𝑓 𝑥1
𝑓 𝑥 = 𝑓 𝑥1 + . 𝑥 − 𝑥1
𝑥2 − 𝑥1

𝑓 110 − 𝑓 105
𝑓 𝑥 = 𝑓 105 + . 𝑥 − 105
110 − 105
143.38 − 120.9
𝑓 𝑥 = 120.9 + . (𝑥 − 105)
75 − 40

We want to find 𝑓(107), so:

143.38−120.9
𝑓 107 = 120.9 + . 107 − 105 = 122.1845 kPa
75−40
b) Direct Method

The direct method of interpolation is based on the following premise: Given 𝑛 + 1 data
points, fit a polynomial of order 𝑛 as given below:
𝑦 = 𝑎𝑜 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + ⋯ + 𝑎𝑛 𝑥 𝑛

through the data, where 𝑎0 , 𝑎1 , … , 𝑎𝑛 are 𝑛 + 1 real constants.

Since 𝑛 + 1 values of 𝑦 are given at 𝑛 + 1 values of 𝑥 , one can write 𝑛 + 1 equations.


Then the 𝑛 + 1 constants, 𝑎0 , 𝑎1 , … , 𝑎𝑛 can be found by solving the 𝑛 + 1 simultaneous
linear equations.
Example 1(Linear Direct Method Interpolation)
Consider the following data to find 𝑓(4) using the direct method interpolation.

The polynomial to be found is of the 1st order and requires two points to evaluate it.

𝑓 𝑥 = 𝑎0 + 𝑎1 𝑥 , so we write:
𝑓 3 = 𝑎0 + 𝑎1 3 = 6 X Y
3 6
𝑓 5 = 𝑎0 + 𝑎1 5 = 12
5 12
Now we have two equations:
𝑎0 + 𝑎1 3 = 6

𝑎0 + 𝑎1 5 = 12 by solving we find 𝑎0 = −3 and 𝑎1 = 3

Hence 𝑓 𝑥 = 𝑎0 + 𝑎1 𝑥  𝑓 𝑥 = −3 + 3𝑥

So, when 𝑦 = 4 , 𝑓 4 = −3 + 3 × 4 = 9
Example 2 (Quadratic Direct Method Interpolation)
Consider the following data which represent the velocity of a car at different time
instants. Using the direct method of a second order (quadratic) interpolation, find the
velocity of the car at time t=25 seconds.
time (s) velocity (m/s)
5 0
15 10
30 16
Example 2 - Solution
The polynomial to be found is of the 2nd order and requires three points to evaluate it.

𝑓 𝑥 = 𝑎0 + 𝑎1 𝑥 +𝑎2 𝑥 2 , so we write:
2
𝑓 5 = 𝑎0 + 𝑎1 5 +𝑎2 5 =2 time (s) velocity (m/s)
𝑓 15 = 𝑎0 + 𝑎1 15 +𝑎2 15 2 = 10
5 2
2
𝑓 30 = 𝑎0 + 𝑎1 30 +𝑎2 30 = 16
15 10
Now we have three equations:
𝑎0 + 5 𝑎1 + 25 𝑎2 = 2
30 16
𝑎0 + 15 𝑎1 +225 𝑎2 = 10
𝑎0 + 30 𝑎1 +900 𝑎2 = 16

by solving we find 𝑎0 = −3.2 , 𝑎1 = 1.12 and 𝑎2 = −0.016

Hence 𝑓 𝑥 = 𝑎0 + 𝑎1 𝑥 +𝑎2 𝑥 2  𝑓 𝑥 = −3.2 + 1.12 𝑥 − 0.016 𝑥 2


2
So, when t=25 , 𝑓 25 = −3.2 + 1.12 25 − 0.016 25 = 14.8 m/s

You might also like