0% found this document useful (0 votes)
45 views39 pages

Lec 1-2 Interpolation

Uploaded by

gemyramadan11
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)
45 views39 pages

Lec 1-2 Interpolation

Uploaded by

gemyramadan11
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/ 39

Faculty of

Engineering

Applied Numerical Analysis


Interpolation
Contents
➢ Mathematical Modeling

and errors (CH 1,4)

➢ Polynomial Interpolation,

Spline Interpolation (CH 17,18)

➢ Least Square Methods (CH 15)

➢ Solution of linear and nonlinear

systems (CH 9, 12)

➢ Numerical differentiation and integration (CH


20,21)

➢ Numerical solution of ODEs and PDEs (CH


22,24)
ACM 502: Numerical Analysis (Fall 2022)
References
ACM 502: Numerical Analysis (Fall 2022)
Contents
➢ Polynomial Interpolation CH 17

4
Interpolation
6
The function f(x) is known at a finite set of discrete values of x.
However, a problem arises when the value of the function is needed at
any value of x between the discrete values in the table.
The actual function is not known and cannot be determined from the
tabular values.

However, the actual function can be approximated by some known


function, and the value of the approximating function can be determined
at any desired value of x. This process is called interpolation

Many types of approximating functions exist. In fact, any analytical


function can be used as an approximating function. Three of the more
common approximating functions are:

1. Polynomials
2. Trigonometric functions
3. Exponential functions
7
Approximating functions should have the following properties:
1. The approximating function should be easy to determine.
2. It should be easy to evaluate, differentiate, and integrate.

There are two fundamentally different ways to fit a polynomial to a set of


discrete data:
1. Exact fits
2. Approximate fits

An exact fit yields a polynomial that passes exactly through all of the
discrete points. This type of fit is useful for small sets of smooth data.

An approximate fit yields a polynomial that passes through the set of


data in the best manner possible, without being required to pass exactly
through any of the data points.
Approximate fits are useful for large sets of smooth data and small 8or
large sets of rough data.
9
10
11
will be the smallest possible when the approximation is centered in the
discrete data because that makes the (x - xi) terms as small as possible,
which makes the product of those terms the smallest possible

12
Interpolation

13
14
Interpolation
Example: Find the polynomial that interpolates

15
Interpolation

16
The main advantage of direct fit polynomials is that the explicit form of the
approximating function is obtained, and interpolation at several values of x
can be accomplished simply by evaluating the polynomial at each value of x.
The work required to obtain the polynomial does not have to be redone for
each value of x.

A second advantage is that the data can be unequally spaced.

The main disadvantage of direct fit polynomials is that each time the degree
of the polynomial is changed, all of the work required to fit the new
polynomial must be redone. The results obtained from fitting other degree
polynomials are of no help in fitting the next polynomial. One approach for
deciding when polynomial interpolation is accurate enough is to interpolate
with successively higher-degree polynomials until the change in the result is
within an acceptable range. This procedure is quite laborious using direct fit
polynomials.
For a high-degree polynomial (n greater than about 4), the
system of equations can be ill-conditioned, which causes large errors in the
values of the coefficients. 17
18
19
20
Interpolation
function yint = Lagrange(x,y,xx)
% Lagrange: Lagrange interpolating polynomial
% yint = Lagrange(x,y,xx): Uses an (n - 1)-order
% Lagrange interpolating polynomial based on n data points
% to determine a value of the dependent variable (yint) at
% a given value of the independent variable, xx.
% input:
% x = independent variable
% y = dependent variable
% xx = value of independent variable at which the
% interpolation is calculated
% output:
% yint = interpolated value of dependent variable
n = length(x);
if length(y)~=n, error('x and y must be same length'); end

21
Interpolation
s = 0;
for i = 1:n
product = y(i);
for j = 1:n
if i ~= j
product = product*(xx-x(j))/(x(i)-x(j));
end
end
s = s+product;
end
yint = s;

>> format long


>> T = [-40 0 20 50];
>> d = [1.52 1.29 1.2 1.09];
>> density = Lagrange(T,d,15)
22
The main advantage of the Lagrange polynomial is that the data may be
unequally spaced.
There are several disadvantages. All of the work must be redone for
each degree polynomial. All the work must be redone for each value of x.
The first disadvantage is eliminated by Neville’s algorithm

23
Neville’s Algorithm

• It is based on a series of linear interpolations. The data do not


have to be in monotonic order, or in any structured order.
However, the most accurate results are obtained if the data are
arranged in order of closeness to the point to be interpolated

Weighted average
on a straight line

24
25
The advantage of Neville’s algorithm over a Lagrange interpolating
polynomial, if the data are arranged in order of closeness to the
interpolated point, is that none of the work performed to obtain a specific
degree result must be redone to evaluate the next higher degree result.

Neville’s algorithm has a couple of minor disadvantages. All of the work


must be redone for each new value of x. The amount of work is
essentially the same as for a Lagrange polynomial.

26
Let’s interpolate for f(3.44) using Neville's linear, quadratic, and cubic
interpolation algorithm. Rearranging the data in order of closeness to the
point x = 3.44 yields the following data:

27
28
Interpolation

A divided difference is defined as the ratio of the difference in the


function values at two points divided by the difference in the values of
the corresponding independent variable.
Thus, the first divided difference at point i is defined as

29
30
Interpolation

31
Interpolation

This entire process can be repeated again and again, and each
time higher interpolating polynomials

32
Interpolation

33
Interpolation

34
35
Interpolation

36
Interpolation
function yint = Newtint(x,y,xx)
% Newtint: Newton interpolating polynomial
% yint = Newtint(x,y,xx): Uses an (n - 1)-order Newton
% interpolating polynomial based on n data points (x, y)
% to determine a value of the dependent variable (yint)
% at a given value of the independent variable, xx.
% input:
% x = independent variable
% y = dependent variable
% xx = value of independent variable at which
% interpolation is calculated
% output:
% yint = interpolated value of dependent variable
% compute the finite divided differences in the form of a
% difference table
n = length(x);
if length(y)~=n, error('x and y must be same length');
end
37
b = zeros(n,n);
Interpolation
% assign dependent variables to the first column of b.
b(:,1) = y(:); % the (:) ensures that y is a column
vector.
for j = 2:n
for i = 1:n-j+1
b(i,j) = (b(i+1,j-1)-b(i,j-1))/(x(i+j-1)-x(i));
end
end
% use the finite divided differences to interpolate
xt = 1;
yint = b(1,1);
for j = 1:n-1
xt = xt*(xx-x(j));
yint = yint+b(1,j+1)*xt;
end

>> format long >> y = log(x);


38
>> x = [1 4 6 5]’; >> Newtint(x,y,2)
Interpolation

… and that’s all for today!

39

You might also like