0% found this document useful (0 votes)
88 views35 pages

Lecture Notes 4-Interpolation

Uploaded by

23146315
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)
88 views35 pages

Lecture Notes 4-Interpolation

Uploaded by

23146315
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/ 35

APPLIED

MATHEMATICS
in MECHANICAL
ENGINEERING

Lecture notes
Ha Le Nhu Ngoc Thanh, Ph.D.
Chapter 4:
INTERPOLATION AND POLYNOMIAL APPROXIMATION

1. Introduction
2. Lagrange interpolating
3. Newton interpolating
4. Spline Interpolation
5. Least Square Method (Reference)

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 2 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

INTRODUCTION
Polynomial problem
A census of the population of the United States is taken every 10 years.

We might ask whether they could be used to


provide a reasonable estimate of the population, ?
say, in 1975 or even in the year 2020. Predictions
of this type can be obtained by using a function
that fits the given data. This process is called
interpolation

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 3 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

INTRODUCTION
Algebraic polynomial
A well-known classes of functions mapping the set of real
numbers into itself is the algebraic polynomials, set of functions
of the form
Pn (x ) an x n an 1x n 1
a1x a0
Where n is a nonnegative integer and a 0 , , an are real constants.
Any given function, there exists a polynomial that is as “close”
to the given function as desired.
yn f (x n )

yk f (x k )

y1 f (x1 )
y0 f (x 0 )
P (x n )

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 4 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

LAGRANGE INTERPOLATION
Lagrange Interpolating polynomial
General Theorem :
If x 0 , x1, , x n are n 1 distinct numbers and is a function whose
yn f (x n )
values are given at these numbers, then a unique polynomial P(x)
of degree n exists with y f (x k )
k

yk f xk P x k , for each k 0,1, ,n y1 f (x1 )


y0 f (x 0 )
This polynomial given by P (x n )

n
P (x ) f (x k )Ln,k (x ) f (x 0 )Ln,0 (x ) f (x n )Ln,n (x )
k 0 Missing: x xk
where, for each k 0, 1, ,n
n x xi (x x 0 )(x x1 ) (x xk 1 )(x xk 1 )(x xn )
Ln,k x
i 0 xk xi (x k x 0 )(x k x1 ) (x k xk 1 )(x k xk 1 )(x k xn )
i k
to simple Ln,k x Lk x

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 5 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

LAGRANGE INTERPOLATION
Lagrange Interpolating polynomial

If we are given only two points i.e. (x 0 , y 0 ) and (x1, y1 )


The maximm we can find is a line which is polynomial of degree 1
To find P1(x ) using Lagrange interpolation
P1(x ) L0y 0 L1y1
x x1 x x0
P1(x ) y0 y1
x 0 x1 x1 x 0
If we are given only three points i.e. (x 0, y 0 ), (x1, y1 ) and (x 2, y2 )
The maximm we can find is a line whihc is polynomial of degree 2
To find P2 (x ) using Lagrange interpolation
P2 (x ) L0y 0 L1y1 L2y2
x x1 x x2 x x0 x x2 x x0 x x1
P2 (x ) y0 y1 y2
x0 x1 x 0 x2 x1 x 0 x1 x2 x2 x 0 x2 x1

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 6 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

LAGRANGE INTERPOLATION
Example 1:

Solution :
xk 2 2.75 4
, k 0,1, 2 3 points poynomial 2nd order
yk f (x k ) 1 2 1 2.75 1 4
x x1 x x2 x 2.75 x 4 2
a) k 0 : L0 (x ) x 2.75 x 4
x0 x1 x 0 x2 2 2.75 2 4 3
x x0 x x2 x 2 x 4 16
k 1 : L1(x ) x 2 x 4
x1 x 0 x1 x2 2.75 2 2.75 4 15
x x0 x x1 x 2 x 2.75 2
k 2 : L2 (x ) x 2 x 2.75
x2 x 0 x2 x1 4 2 4 2.75 5
2
P (x ) f (x k )Lk (x ) f (x 0 )L0 (x ) f (x 1 )L1(x ) f (x 2 )L2 (x )
k 0
1 2 1 16 1 2
x 2.75 x 4 x 2 x 4 x 2 x 2.75
2 3 2.7515 4 5
1 2 35 49 1 2 35 49
P (x ) x x b) P 3 3 3 0.32955 f (3)
22 88 44 22 88 44
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 7 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

LAGRANGE INTERPOLATION
Example 2:
Find the interpolating polynomial that passes through (2, 5), (3, 7), (5, 8)
and find a value at x 4
Solution :
xk 2 3 5
, k 0,1, 2 3 points poynomial 2nd order
yk f (x k ) 5 7 8
x 3 x 5 1 1 2 8
a) k 0 : L0 (x ) x 3 x 5 x x 5
2 3 2 5 3 3 3
x 2 x 5 1 1 2 7
k 1 : L1(x ) x 2 x 5 x x 5
3 2 3 5 2 2 2
x 2 x 3 1 1 2 5
k 2 : L2 (x ) x 2 x 3 x x 1
5 2 5 3 6 6 6
2
P (x ) f (x k )Lk (x ) f (x 0 )L0 (x ) f (x1 )L1(x ) f (x 2 )L2 (x )
k 0
1 2 8 1 2 7 1 5
5 x x 5 7 x x 5 8 x2 x 1
3 3 2 2 6 6
1 2 9 1 2 9
P (x ) x x 2 b) P 4 4 4 2 8
2 2 2 2
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 8 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

LAGRANGE INTERPOLATION
(MATLAB simulation) n x xi (x x 0 )(x x1 ) (x xk 1 )(x xk 1 )(x xn )
Ln,k x
i 0 xk xi (x k x 0 )(x k x1 ) (x k xk 1 )(x k xk 1 )(x k xn )
i k

clc; clear all; close all;


X=input('Enter list of x = ');
Y=input('Enter list of y = '); %% write a polynomial under form: ax^n+bx^-1+....
F=flip(P);
n= length(X); fprintf('Polynomial is: ');
L=[]; for j=n:-1:2
for k=1:n %for row fprintf('+(%.3fx^%d)',F(j),j-1)
Lk=1; end
fprintf('+(%.3f)\n',F(1))
for i=1:n %for making polynomial %% Plot curve
if k~=i x=linspace(X(1),X(n),100);
Lk=conv(Lk,poly(X(i)))/(X(k)-X(i)); y=polyval(P,x);
end plot(x,y)
hold on
end plot(X,Y,'o')
L=[L;Lk]; % update Lk to L %% Interpolate at an arbitrary point
P(k,:)=Lk*Y(k) ; n
P0=input('Enter a point want to approximate P0 = ');
end P (x ) f (x k )Ln,k (x ) f (x 0 )Ln,0 (x ) f (x n )Ln,n (x ) A=polyval(P,P0);
k 0 fprintf('value of approximation is: %.4f\n',A)
L % Coefficients of Lk
P % Coefficients of polynomial Pk
P=sum(P);

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 9 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

LAGRANGE INTERPOLATION
Example 3.
Using Lagrange’s interpolation formula to find y(1.5) from the
Calculator :
following table:
xk 0 1 2 5 xg A xg B xg C
Y Y :F F Y
X A X B X C
yk f xk 2 3 12 147
input : A x 1, B x 2 ,C x 3, X x 0 ,Y Y0 , F 0,

Solution: given n=4, x g =1.5 the Lagrange polynomial for n=4


can be given by:
yg P (x g ) L0y 0 L1y1 L2y2 L3y 3
xg x1 x g x2 xg x3 xg x 0 xg x1 x g x2 xg x 0 xg x1 x g x3
y0 y1 y2
x0 x1 x 0 x2 x 0 x3 x1 x 0 x1 x 2 x1 x3 x2 x 0 x2 x1 x 2 x3
xg x 0 xg x1 x g x2
y3
x 3 x 0 x 3 x1 x 3 x 2
0.175 1.9687 5.25 0.9187 6.125

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 10 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

LAGRANGE INTERPOLATION
Example 4.
Using Lagrange’s interpolation formula to find y(3.5) from the
following table:
xk 1 2 3 4 5
yk f xk 1 4 9 16 25

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 11 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

LAGRANGE INTERPOLATION
Error evaluation of Lagrange interpolating polynomial.
Suppose x 0 , x1 , x n are distinct nunbers in the interval [a, b ] and f (x ) continuous
n 1
and f in a, b . Then for each x in [a, b ], a number (generally unknown)
between x 0 , x1 , x n , and hence in (a, b), exists with
f (n 1) n f (n 1)
f (x ) Pn (x ) x xi Pn (x ) x x0 x x1 x xn
n 1! i 0 n 1!
Error
where P (x ) is the interpolating polynomial of f (x )
f (n 1)
n
Boudary error f (x ) f (x ) Pn (x ) x xi
n 1! i 0
n
M
x xi
n 1! i 0
Absolute error at x k f (x k ) Pn (x k )
where f (n 1)
M, x x 0, xn
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 12 Mechanical Engineering
Introduction
Lagrange Interpolation f (n 1) n
Newton interpolation f (x ) P (x ) x xi
Spline interpolation
n 1! i 0
LAGRANGE INTERPOLATION Error

Error evaluation of Lagrange interpolating polynomial.


Example 5
In example 2, we found the second Lagrange polynomial for f (x ) 1 x on [2, 4] using the nodes
x 0 2, x1 2.75, and x 2 4.Determine the error form for this polynomial, and the maximum
error when the polynomial is used to approximate f (x ) for x [2, 4]
Solution:
2
Because f (x ) 1x f (x ) x ,
3
f (x ) 2x
4
f (x ) 6x
f 4
Error : E x x0 x x1 x x2 x 2 x 2.75 x 4 , [2, 4]
3!
4
It can be seen : [2, 4] 2 1 16 x 7 3 7 2
1 35 2 49 y 0 0
Maximum error of approximation : E x3 x x 22 25 9
16 4 2 y
35 2 49 35 49 108 16
Let : g(x ) x3 x x 22 g (x ) 3x 2 x E
1 9 3
0.00586
4 2 2 2 16 16 512

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 13 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation .

LAGRANGE INTERPOLATION
Example 6:
xk 1 2 3 4 5
Given function: y f (x ) (x 2) cos x with
3 yk f xk 1.5 2 5 3 3.5
a)Find interpolating polynomial for function f (x ),
b) Find f (2.5) and evaluating the absoulute error and boundary error

Solution:
a ) P (x ) L0y 0 L1y1 L2y2 L3y 3 L4y 4
x 2 x 3 x 4 x 5 x 1 x 3 x 4 x 5
1.5 ( 2)
24 6
x 1 x 2 x 4 x 5 x 1 x 2 x 3 x 5
( 5) ( 3)
4 6
x 1 x 2 x 3 x 4
(3.5)
24
4
P (x ) 0.208x 2.833x 3 11.542x 2 14.417x 4
f (2.5) P (2.5) 3.9609

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 14 Mechanical Engineering
Introduction
(n ) n
a n cos ax
Lagrange Interpolation
Newton interpolation cos(ax b) b
Spline interpolation 2
LAGRANGE INTERPOLATION
Example 6:
b)evaluating error
(n ) n
Leibniz : uv C nk u (k )v (n k)

k 0
C n0uv (n ) C n1 u v (n 1)
C n2u v (n 2)
C nn u (n )v
n!
C nk
k! n k !
We have: f (x ) (x 2)cos x (5) (4)
3 f (5)(x ) (x 2) cos x 5 cos x
(5) (5) (4) 3 3
f (5)(x ) (x 2)cos x C 50 (x 2) cos x C 51(x 2) cos x (5)
3 3 3 5 5
cos x 3 cos x 3 5 2 3 cos x 3 2
(3) 3
C 52 (x 2) cos x (4)
3 4 4
0 cos x 3 cos x 3 4 2 3 cos x 3
3
5! 5!
C 50 1, C 51 5,
0!(5!) 1!(4 !)
5 4
f (5)(x ) (x 2) 3 cos x 3 2 5 3 cos x 3
5 4
f (5)(x ) (x 2) 3 cos x 3 2 5 3 cos x 3 , x [1, 5]
5 4 1
7 3 .1 5 3 11.829
2
Absolute error : f (2.5) P (2.5)
f (5)(x ) 11.829
Boundary Error : f (2.5) P (2.5) x x0 x x5 2.5 1 2.5 5 0.1338 The boundary error is 0.1338
(n 1)! 5!
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 15 Mechanical Engineering
Introduction
(n ) n
a n cos ax
Lagrange Interpolation
Newton interpolation cos(ax b) b
Spline interpolation 2
LAGRANGE INTERPOLATION
Example 7:

Solution :
To compute an boundary error for the approximation of the given function in the interval [0,0.8],
we use the following error formula for Lagrange polynomial degree four
f (5) 4 f (5)
f (x ) P4 (x ) . x xi . x x0 x x1 x x2 x x3 x x4
5! i 0 5!
f (5) x cos(x ) 1
1
*boundary error at x=0.28: f (0.28) P4 (0.28) . 0.28 0 0.28 0.2 0.28 0.4 0.28 0.6 0.28 0.8
5!
3.7 10 6
6
*Absolute error at x=0.28: f (0.28) P4 (0.28) sin(0.28) P4 (0.28) 0.2763556 0.2763591 3.5 10
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 16 Mechanical Engineering
Introduction
(n ) n
a n cos ax
Lagrange Interpolation
Newton interpolation cos(ax b) b
Spline interpolation 2
LAGRANGE INTERPOLATION
Example 8:
Consider the following table having the data for f (x ) e 3x cos 2x
x 0.2 0.4 0.5
f (x ) 2.7432 4.0168 5.2022
Find the approximaton of f (0.45) using the best quadratic Lagrange interpolation formula and also estimate an
boundary error and absolute error for the approximation
Solution :
we can find a Lagrange polynomial: P2 (x ) 11.28x 2 x 2.452
Absolute error : f (0.45) P2 (0.45) 0.0097
Boundary error :
f (3)(x )
f (x ) P2 (x ) x x0 x x1 x x2
3!
where: f (x ) 27e 3x 8 sin 2x
x 0.2, 0.5 f (x ) 27e 3(0.5) 8 sin 2(0.5) 127.7374
127.7374
Boundary error can be computed by: f (0.45) P2 (0.45) 0.45 0.2 0.45 0.4 0.45 0.5 0.0133
3!
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 17 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

NEWTON’S INTERPOLATING POLYNOMIAL


Newton’s interpolating polynomial:
Given x i [a, b ], i 0, n,(n 1)points. Determine a nth-order polynomial Pn (x ), Pn (x i ) yi
Pn (x ) a 0 a1(x x 0 ) a2 (x x 0 )(x x1 ) an (x x 0 )(x x1 ) (x x n 1 )
Problem is to determine : where:
a , i 0, n, First finite divided difference:
i
a0 Pn (x 0 ) P xi P xj
P xi , x j
a1 Pn (x1, x 0 ) xi xj
a2 Pn (x 2 , x1, x 0 ) Second finite divided difference:
P xi , x j P x j , xk
an Pn (x n , x n 1, , x 1, x 0 ) P xi , x j , xk
xi xk

nth finite divided difference:


P x n , x n 1, , x1 P x n 1, , x 1, x 0
P x n , x n 1, , x 1, x 0
xn x0
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 18 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

NEWTON’S INTERPOLATING POLYNOMIAL


Easy to understand

Pn (x ) a0 a1(x x0) a2 (x x 0 )(x x1 ) an (x x 0 )(x x1 ) (x xn 1)

P x1 P x0 P x2 P x1 P x3 P x2
a0 P x 0 , a1 P x 1, x 0 , P x 2 , x1 , P x 3, x2
x1 x 0 x 2 x1 x3 x2
P x 2 , x1 P x 1, x 0 P x 3, x2 P x 2 , x1 P x 3 , x 2 , x1 P x 2 , x 1, x 0
a2 P x 2 , x 1, x 0 , P x 3 , x 2 , x1 a3 P x 3 , x 2 , x 1, x 0
x2 x0 x3 x1 x3 x0

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 19 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

NEWTON’S INTERPOLATING POLYNOMIAL


MATLAB code %% Generate a polynomial and display it
C=a(1,n);
clc; clear all; close all;
for k=n-1:-1:1
%% Compute Newton's interpolation
C=conv(C,poly(x(k)));
x=input('Enter list of x = ');
m = length(C);
y=input('Enter list of y = ');
C(m)=C(m)+a(1,k);
P0=input('Enter point of approxmation: x_P0 = ');
end
n = length(x);
format rat % display under factional function
if length(y)~=n
fprintf('Coefficient of interpolating polynormial: ')
error('x and y must be same length')
C
end
% write a polynomial under form: ax^n+bx^-1+....
a = zeros(n,n);
F=flip(C);
a(:,1)=y(:);
fprintf('Polynomial is: ');
for j=2:n
for j=n:-1:2
for i=1:n-j+1
fprintf('+(%.3fx^%d)',F(j),j-1)
a(i,j)=(a(i+1,j-1) - a(i,j-1))/(x(i+j-1)-x(i));
end
end
fprintf('+(%.3f)\n',F(1))
end
% compute P(x0)
fprintf('Matrix of Coefficient: ')
y0 = polyval(C,P0);
a
fprintf('Approximation value at given data point is: P(x0) =
fprintf('Coefficient of Newton interpolation: ')
%.4f\n', y0)
A=a(1,:)
%% Plot
X=linspace(x(1),x(n),100);
Y=polyval(C,X);
plot(X,Y,'blue')
hold on
plot(x,y,'ro')

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 20 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

NEWTON’S INTERPOLATING POLYNOMIAL


Example 1:
Fit a third-order polynomal to the four points used as follows:
x 1 4 6 5
f (x ) P (x ) 0 1.386924 1.791759 1.6094381
estimate f (x ) ln x , at x 2
Solution :
xi P xi First Second Third
1.386924 0 0.2027326 0.4620981 0.02041100 0.05187311
1 0 0.4620981 0.05187311 0.007865529
4 1 6 1 5 1
1.791759 1.386924 0.1823216 0.2027326
4 1.386924 0.2027326 0.02041100 0
6 4 5 4
1.609438 1.791759
6 1.791759 0.1823216 0 0
5 6
5 1.609438 0 0 0
P3 (x ) 0 0.4620981 x 1 0.05187311 x 1 x 4 0.00786629 x 1 x 4 x 6
P3 (2) 0.6287
0.6287 ln(2)
True error 0.6287 ln(2) 0.0644, Relative error 9.1%,
ln(2)
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 21 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

NEWTON’S INTERPOLATING POLYNOMIAL


Error Estimation for Newton’s polynomial
If we had not known the true value (lnx), we can estimate the error as follows
Rn x Pn 1 x n 1, x n , x n 1, , x0 x x0 x x1 x xn

Example 2:
Fit a third-order polynomal to the four points used as follows:
x 1 4 6 5
f (x ) P (x ) 0 1.386924 1.791759 1.6094381
estimate error at x 2

Solution :
From newton's interpolating polynomial:
P3 (x ) 0 0.4620981 x 1 0.05187311 x 1 x 4 0.00786629 x 1 x 4 x 6
Estimate error (n 2) : R2 (x ) 0.00786629 x 1 x 4 x 6
R2 (2) 0.00786629 2 1 2 4 2 6 0.0629 true error 0.0644

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 22 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

NEWTON’S INTERPOLATING POLYNOMIAL


Example 3:
x 1 2 4 7 8
Given data as table:
f (x ) P (x ) 9 41 189 9 523
a) Find a polynomial using Newton's interpolation method
b) Find P(x), and estimate error at x 5
Solution :
a) Newton's interpolating polynomial
xi P xi 1st 2nd 3rd 4th
41 9 74 32 28 14 14 7 P4 (x ) 9 32 x 1 14 x 1 x 2
1 9 32 14 7 1
2 1 4 1 7 1 8 1 7 x 1 x 2 x 4
189 41 66 74 112 28 1. x 1 x 2 x 4 x 7
2 41 74 28 14 0
2 1 7 2 8 2
9 189 514 66 b) P4 (5) 245
4 189 66 112 0 0
7 4 8 4 Estimate error:
523 9 R 3 (5) 1. 5 1 5 2 5 4 5 7 24
7 9 514 0 0 0
2 1 R 3 (5) 24
8 523 0 0 0 0

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 23 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

NEWTON’S INTERPOLATING POLYNOMIAL


Example 4:
x 2 3.5 4 5.5 6 7 8
Given data as table:
P (x ) 4 7 8 11 15 19 23
a) Find a polynomial using Newton's interpolation method
b) Find P(x), and estimate error at x 4.6
Solution :
P6 (x ) 4
a) Newton's interpolating polynomial 2 x 2

xi P xi 1st 2nd 3rd 4th 5th 6th 0 x 2 x 3.5


0. x 2 x 3.5 x 4
2 4 2 0 0 3 10 149 630 94 945 3
x 2 x 3.5 x 4 x 5.5
3.5 7 2 0 6 5 278 315 227 630 0 10
149
x 2 x 3.5 x 4 x 5.5 x 6
4 8 2 3 17 9 133 180 0 0 630
94
5.5 11 8 8 3 16 15 0 0 0 x 2 x 3.5 x 4 x 5.5 x 6 x 7
945
6 15 4 0 0 0 0 0
b) P6 (4.6) 7.7091
7 19 4 0 0 0 0 0 Estimate error:
94
8 23 0 0 0 0 0 0 R 5 (4.6) 5 2 5 3.5 5 4 5 5.5 5 6 5 7 0.4476
945

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 24 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
Spline Interpolation definition
nth-order polynomials were used to interpolate
between n + l data points. For example, for eight
points, we can derive a perfect seventh-order
polynomial. This curve would capture all the
meanderings (at least up to and including
seventh derivatives) suggested by the points.
Given : x 0 , x1, , x n , n 1 points Pn (x )
ex: 8 points P7 (x )
x 0 , x1, , x n P7 (x )
However, there are cases where these functions
can lead to erroneous results because of round-off
error and overshoot. An alternative approach is
to apply lower-order polynomials to subsets of
data points. Such connecting polynomials are
called spline functions.

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 25 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
Spline Interpolation definition
For n data points (i=1,2,…,n), there are (n - 1) intervals. Each interval i has two points, and has its own
spline function 𝑠𝑖 (𝑥) .
Spline si (x ) can be:
Linear(First-Order) splines.
Quadratic(Second order) splines.
Cubic (Third order) splines.

Notice that there are n - 1 intervals and n data points

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 26 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
1. Linear spline
For linear splines, each function is merely the straight line connecting the two points at each end of the
interval, the straight line is given by:
fi 1 fi
si (x ) fi (x x i ), where fi is shorthand for fi (x )
xi 1 xi s1(x )
s 3 (x )
s2 (x )
Example 1:
Fit the data in Table with first-order spline. Evaluate the function at x = 5.
i xi fi Solution :
f2 f1 1 2.5
1 3.0 2.5 In the first interval from 3.0 to 4.5: s1(x ) f1 x x1 2.5 x 3
x2 x1 4.5 3.0
2 4.5 1.0
f3 f2 2.5 1.0
3 7.0 2.5 In the second interval from 4.5 to 7.0: s2 (x ) f2 x x2 1.0 x 4.5
x3 x2 7.0 4.5
4 9.0 0.5 f4 f3 0.5 2.5
In the third interval from 7.0 to 9.0: s 3 (x ) f3 x x3 2.5 x 7.0
x 4 x2 9.0 7.0
2.5 1.0
x 5 4.5, 7 x 5 s2 (x ) s2 (5) 1.0 5 4.5 1.3
7.0 4.5
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 27 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
2. Quadratic spline (Second order spline)
For second-order spline, each function is merely the second-order connecting the two points at each end of
2
the interval, the second-order spline is given by: si (x ) ai bi (x x i ) ci (x x i ) , i 1, 2, , n, Interval:(n 1)

* The function si (x ) pass through all the points x i , f (x i ) .


si 1 (x )
2
fi f (x i ) ai bi x i xi ci x i xi ai fi
2
Function becomes: si (x ) fi bi x xi ci x xi
Because knot x i 1, f (x i 1) si (x )
2
fi 1 f xi 1 fi bi x i 1 xi ci x i 1 xi (*)
Let hi xi 1 xi
(*)
fi 1 fi bi hi ci hi2 , where i 1, 2... n 1
Notice that there are n - 1 intervals and n data points

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 28 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
2. Quadratic spline (Second order spline)
si 1 (x )
* Smooth condition
2
si (x ) fi bi x xi ci x xi
2
si 1(x ) fi 1 bi 1 x xi 1 ci 1 x xi 1
si (x ) si 1(x )
x xi 1
x xi 1

bi 2ci x i 1 xi bi 1 2ci 1 xi 1 xi 1
bi 2ci x i 1 xi bi 1
bi 2ci hi bi 1, where i 1, 2, ... n 2 Notice that there are n - 1 intervals and n data points
3.Assume that the second derivative
is zero at the first point: s1(x ) 2c1 0 c1 0
i x f
Example 2: i i
1 3.0 2.5
Fit the data in Table with second-order spline.
2 4.5 1.0
Evaluate the function at x = 5.
3 7.0 2.5
4 9.0 0.5
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 29 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
Solution:

we have n 4 data points, n 1 3 intervals, and c1 0


f1 2.5 h1 4.5 3.0 1.5
b1h1 c1h12 f2 f1
f 1.0 h2 7.0 4.5 2.5
b2h2 c2h22 f3 f2 (*), where 2
f3 2.5 h3 9.0 7.0 2.0
b3h3 c3h32 f4 f3 f4 0.5 c1 0
Smooth condition:
b1 b2 2c1h1 0
(**)
b2 b3 2c2h2 0
1.5b1 1.5 4.5b1 1.5 1.5 0 0 0 0 b1 1.5
2.5b2 2.52 c2 1.5 2.5b2 2.52 c2 1.5 0 2.5 0 6.25 0 b2 1.5
(*)&(**)
2b3 4c3 2 2b3 4c3 2 0 0 2 0 4 b3 2
b1 b2 b1 b2 0 1 1 0 0 0 c2 0 i xi fi
b2 5c2 b3 b2 b3 5c2 0 0 1 1 5 0 c3 0 1 3.0 2.5
2 4.5 1.0
b1 1, b2 1, b3 2.2, c2 0.64, c3 1.6 3 7.0 2.5
4 9.0 0.5

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 30 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
Summarization

bi hi ci hi2 fi 1 fi bi bi 1 2ci hi 0
c1 0
where i 1, 2... n 1 where i 1, 2,... n 2
b1h1 f2 f1 b1 b2 0
n points b2h2 c2h22 f3 f2 b2 b3 2c2h2 0
n 1 spline
hi xi 1 xi b h
i i ci hi2 fi1 fi bi bi 1 2ci hi 0
bn 1hn cn 1hn2 1 fn fn bn 2 bn 1 2cn 2hn 2 0
1 1

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 31 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
3. Cubic spline
si (x ) ai bi (x x i ) ci (x x i )2 di (x x i )3 , i 1, 2, , n, data points , Interval:(n 1)
ai , bi , ci and di are computed by:
1 0 0 0 c1 0
h1 2(h1 h2 ) h2 0 c2 3( f [x 3 , x 2 ] f [x 2 , x1 ])
0 0
0 0 hn 2 2(hn 2 hn 1 ) hn 1 cn 1 3( f [x n , x n 1] f [x n 1, x n 2 ])
0 0 0 0 1 cn 0
n n
fi fj
where f [x i , x j ] , hi xi 1 xi
xi xj
i xi fi
fi 1 fi hi ci 1 ci
and ai fi ; bi 2ci ci ; di 1 3.0 2.5
1
hi 3 3hi 2 4.5 1.0
Example 3:
Fit the data in Table with third-order spline. Evaluate the function at x = 5. 3 7.0 2.5
4 9.0 0.5

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 32 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
Solution:

1 0 0 0 c1 0
h1 2 h1 h2 h2 0 c2 3 f [x 3 , x 2 ] f [x 2 , x1 ]
0 h2 2 h2 h3 h3 c 3 3 f [x 4 , x 3 ] f [x 3 , x 2 ]
0 0 0 1 c4 0
where
f1 2.5 h1 4.5 3.0 1.5 f [x 2 , x1 ] f2 f1 x2 x1 1
f2 1.0 h2 7.0 4.5 2.5 f [x 3 , x 2 ] f3 f2 x3 x2 0.6
,
f3 2.5 h3 9.0 7.0 2.0 f [x 4 , x 3 ] f4 f3 x4 x3 1
f4 0.5 c1 0
1 0 0 0 c1 0 c1 0
1.5 8 2.5 0 c2 4.8 c2 0.83954
i xi fi
0 2.5 9 2 c3 4.8 c3 0.76654
1 3.0 2.5
0 0 0 1 c4 0 c4 0 2 4.5 1.0
3 7.0 2.5
4 9.0 0.5
Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 33 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

SPLINE INTERPOLATION
Example 4: x 0 1 2 3
Given data points
f (x ) ex 1 e e2 e 3
Fit the data by cubic spline
fi fi hi
Solution: ai fi a1 1, a2 e, a 3 e 2 ; bi 1
2ci ci 1
hi 3
1 0 0 0 c1 0
f2 f1 h1 e 1 1
h1 2 h1 h2 h2 0 c2 3 f [x 3 , x 2 ] f [x 2 , x1 ] b1 2c1 c2 0.757 1.4659
h1 3 1 3
0 h2 2 h2 h3 h3 c 3 3 f [x 4 , x 3 ] f [x 3 , x 2 ] f3 f2 h2 e2 e 1
b2 2c2 c3 2 0.757 5.830 2.2228
0 0 0 1 c4 0 h2 3 1 3
where f4 f3 h3 e3 e2 1
b3 2c3 c4 2 5.830 8.8098
f1 1 h1 1 f [x 2 , x1 ] f2 f1 x2 x1 e 1 h3 3 1 3
ci ci
f2 e h2 1 f [x 3 , x 2 ] f3 f2 x3 x2 e2 e And : di 1
, 3hi
f3 e2 h3 1 f [x , x ] f4 f3 x4 x3 e3 e2 c2 c1 c3 c2
4 3 0.757 5.83 0.757
d1 0.2523 ; d2 1.691
f4 e 3 c1 0 3h1 3 3h2 3
1 0 0 0 c1 0 c1 0 c4 c3 5.83
d3 1.9433
2 3h3 3
1 4 1 0 c2 3(e 2e 1) c2 0.757
3 2 s1(x ) 1 1.4659x 0.2523x 2 , x [0,1]
0 1 4 1 c3 3(e 2e e) c3 5.830
2 3
0 0 0 1 c4 c4 0 s2 (x ) 2.718 2.2228 x 1 0.757 x 1 1.691 x 1 , x [1, 2]
0
2 3
s 3 (x ) 7.389 8.809 x 2 5.83 x 2 1.9433 x 2 ,x [2, 3]

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 34 Mechanical Engineering
Introduction
Lagrange Interpolation
Newton interpolation
Spline interpolation

Exercises
Exercise 1:
Given data points

a) Calculate f(2.8) using Newton’s interpolating polynomials and estimate error


b) Develop a quadratic splines and predict f(3.4) and f(2.2)
Exercise 2:
Given data points

a) Calculate f(4) using Newton’s interpolating polynomials and estimate error


b) Develop a cubic splines and predict f(4) and f(2.5)
Exercise 3:
Given data points
a) Fit a cubic spline
b) Determine y(5)
Exercise 4: Generate eight equally spaced points from the function f (t ) sin2 t
For t=0 to 2𝜋. Fit the data with
a) Seventh-order interpolating polynomial
b) Cubic spline

Applied Mathematics in
Ph.D. Ha Le Nhu Ngoc Thanh 35 Mechanical Engineering

You might also like