0% found this document useful (0 votes)
58 views14 pages

01 Interpolation 1

Interpolation is a method for constructing new data points within a range of discrete known data points. It is commonly used to estimate the value of a function for intermediate values between known data points obtained through sampling or experimentation. There are different types of interpolation including linear, polynomial, spline, and rational interpolation. Polynomial interpolation involves fitting a polynomial function to the known data points, with the order of the polynomial depending on the number of points. Newton interpolation constructs a polynomial using difference quotients calculated from the known data points in a tabular form.
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)
58 views14 pages

01 Interpolation 1

Interpolation is a method for constructing new data points within a range of discrete known data points. It is commonly used to estimate the value of a function for intermediate values between known data points obtained through sampling or experimentation. There are different types of interpolation including linear, polynomial, spline, and rational interpolation. Polynomial interpolation involves fitting a polynomial function to the known data points, with the order of the polynomial depending on the number of points. Newton interpolation constructs a polynomial using difference quotients calculated from the known data points in a tabular form.
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/ 14

Interpolation

Author: dr inż. Robert Szmurło


1 / 14
Interpolation


In the mathematical field of numerical
analysis, interpolation is a method of
constructing new data points within the
range of a discrete set of known data points.


In engineering and science, one often has
a number of data points, obtained by sampling
or experimentation, which represent
the values of a function for a limited number
of values of the independent variable.
It is often required to interpolate (i.e., estimate) the value of that function for
an intermediate value of the independent variable.

2 / 14
Example


Polynomial interpolation – the order of the polynomial depends on the
number of input points (support points). If n is the number of points then the
order polynomial is n-1.

3 / 14
Types of interpolation


Linear interpolation (the interpolating function depend linearly on the
parameters ai)

– a) polynomial interpolation

b) trigonometric interpolation

– c) spline interpolation (with a


special case of cubic spline)


Rational interpolation


Exponential interpolation

4 / 14
Polynomial interpolation (Vandermonde matrix)


Let we denote the polynomial P(x)

● For n+1 arbitrary support points (xi,fi), i=0,1,…,n and


xi≠xk for i≠k there exists a unique polynomial P with


This allows us to construct a system of n linear
equations with n unknowns

● Which can be solved for a0, a1, …, an


– a0 = 1.000, a1 = 1.8333, a2 = -1.0000, a3 = 0.1667
5 / 14
MATLAB code
function L02_lagrange
xin = [0 1 2 4];
yin = [1 2 2 3];

xdense = linspace( min(xin)-0.5, max(xin) + 0.5, 100)


ydense = zeros(100,1);

for i = 1:length(xdense)
ydense(i) = myvandermonde( xdense(i), xin, yin);
end

plot(xin, yin, 'or', xdense, ydense, 'b');


end

function y = myvandermonde(x, xin, yin)


%A = [ 1 xin(1) xin(1)^2 xin(1)^3
% 1 xin(2) xin(2)^2 xin(2)^3
% 1 xin(3) xin(3)^2 xin(3)^3
% 1 xin(4) xin(4)^2 xin(4)^3 ];
n = length(xin);
A = zeros(n);
for r = 1:n
for c = 1:n
A(r, c) = xin(r)^(c-1);
end
end
b = yin';
a = A \ b;

% y = a(1) + a(2) * x + a(3) * x^2 + a(4) * x^3;


y = 0;
for i = 1:n
y = y + a(i) * x^(i-1);
end
end
6 / 14
Lagrange interpolation


Let we denote the polynomial p(x)

● For n+1 arbitrary support points (xi,fi), i=0,1,…,n and


xi≠xk for i≠k there exists a unique polynomial P with


To find this polynomial we will construct p(x)
explicitly with the help of polynomials Li(x) for
which:


The following Lagrange polynomials satisfy this
condition

7 / 14
Example


Find Lagrange interpolating polynomial


Answer

Try to find other Lagrange


polynomials yourself. Check the
solution:

8 / 14
Example MATLAB code

x = [0 1 2 4]
y = [1 2 2 3]
n = length(x);

% xd = 0:0.04:4; % dense vector of x coordinates - only for graphical presentation


xd = linspace(min(x)-0.5,max(x)+0.5, 50); % generate 50 equally spaced points between -0.5 and 4.5
yd = []; % declare en empty vector (it will be filled in within the loop below
for k=1:length(xd) % iterate over all elements of vector xd
xval = xd(k);
s = 0;
for i = 1:n
p = 1;
for j = 1:n
if (i ~= j)
p = p * (xval - x(j)) / (x(i) - x(j));
end
end
s = s + y(i) * p;
end
yd(k) = s;

end
yd; % just to print the contents of vector yd to
% the screen
plot(x,y, 'or', xd, yd, 'b') % plot x,y with circles,

9 / 14
Newton interpolation


Earlier presented Lagrange interpolation has the following limitations:

– If the number of data has to be increased we cannot reuse previous calculations.


– The computational effort required is significant for a single interpolation.
– The estimation of error in interpolation is not easy.


The Newton’s divided-difference (difference quotient) overcomes these
limitations.

The Newton’s polynomial is of the following form:

10 / 14
Newton interpolation – difference quotient


Let we define a set of difference quotients (divided differences)


Now let we construct the table with difference quotients of growing order as
the column index grow

11 / 14
Example


Find Newton interpolating polynomial


Answer

12 / 14
MATLAB code
function L04_newton function a = newton_coeffs(xp, yp)
xp = [0 1 2 4]; n = length(xp);
yp = [1 2 2 3]; A = zeros(n, n+1);
A(:,1) = xp;
xd = linspace( min(xp), max(xp), 50); A(:,2) = yp;
yd = zeros(length(xd), 1); for c = 3:n+1
for r = c-1:n
A(r,c)=(A(r,c-1)-A(r-1,c-1))/(A(r,1)-A(rc+2,1));
%for i=1:length(xd) end
% x = xd(i); end
% yd(i) = 1 + 1*(x-0) - 1/2*(x-0)*(x-1) + 1/6*(x-0)*(x- a = zeros(n,1);
1)*(x-2);
for i = 1:n
%end
a(i) = A(i, i+1);
a = newton_coeffs(xp, yp);
end
yd = newton_polyval(a, xp, xd);
end

plot(xp, yp, 'o', xd, yd, '.');


end

function y = newton_polyval(a, xp, x)


y = zeros(length(x), 1);
for i = 1:length(x) A =
s = 0;
for j=1:length(a) 0 1.0000 0 0 0
p = 1; 1.0000 2.0000 1.0000 0 0
for k=1:(j-1) 2.0000 2.0000 0 -0.5000 0
p = p * (x(i) - xp(k)); 4.0000 3.0000 0.5000 0.1667 0.1667
end
s = s + a(j) * p;
end
y(i) = s;
end
end

13 / 14
Thank you

Homework

Solve all presented here examples on your own on a sheet of paper.

14 / 14

You might also like