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

Course No.

: EEE 212

Group No.:06

Course Title: Numerical Technique Laboratory

Name of the Assignment: EXPLANATION OF THE ALGORITHM OF NEWTONS

INTERPOLATION. GENERATION OF A SMOOTH


CURVE FOR SOME GIVEN DATA POINTS, USING
NEWTON'S INTERPOLATION.

Name: Md. Tahsin Mostafiz


Student ID: 201106109
Department: EEE
Level:2 Term: 2
Partner Students ID: 2011061110

Objective:

The objective of this experiment is to


Explanation of the algorithm of Newton's interpolation.
For the following data points using Newton's interpolation a smooth curve
has to be generated:
(-1, 2), (0, 1), (1,-2), (2, 3), (3, 6).
Figures and Code
Newton polynomial Interpolation:
To construct and evaluate the Newton polynomial of degree n that passes
through the n +1 points (xk , y k ) = (xk , f (xk )) for k = 0,1n :

This polynomial Pn(x) is said to be a Newton Polynomial with n centers x0, x1 to


xn-1. It involves sums of products of linear factors upto:
an(x-x0)(x-x1)(x-x2)(x-xn-1)

To construct and evaluate the Newton polynomial of degree n that passes


through the n +1 points, let us take (xk , y k ) = (xk , f (xk )) for k = 0,1n :

where

CODE:
clc;
clear all;
close all;
x = [-1 0 1 2 3];
y = [2 1 -2 3 6];
n = length(x);
%calculating the divided difference table. The first column is
done separately to maintain the next loop's initializations.
for i=1:n
d(i,1) = y(i);
end
for j=2:n
for k=j:n
d(k,j)=(d(k,j-1)-d(k-1,j-1))/(x(k)-x(k-j+1));
%calculating values of d
end
end
%creating a 2D array to keep track of the product of divided
difference and polynomial before that difference.
s=zeros(n,n);
for i=1:n
p=1;
if i~=1
for k=1:i-1
a = [1 -x(k)]; %Here 1 is the co-effecient of the
variable x.
p = conv(a,p); %polynomials which will be multiplied
by co-efficients d.
end
end
p=p*d(i,i);
f = fliplr(p); % p has been flipped left to right to keep
the constants in the leftmost column.
for j =1:length(p)

s(i,j) = s(i,j)+f(j); %creating the array of

p*d

end
end
A = fliplr(s); % flipped again to keep the higher degree of xs
co-efficients in the leftmost coloumn.
for j = 1:n
res(j) = sum(A(:,j)); %adding the co-efficients of same
column
end
disp(res);
x1 = x(1):.1:x(n); % value of x has been incremented from first
element of x to last with .1 increment.
plot(x,y,'o',x1,polyval(res,x1)); %plotting values
grid on
RESULT:
The following data was shown in command window after running the code:

So the given data points follow the polynmial provided below:


0.8333 4 + 3.3333 3 0.1667 2 5.3333 + 1.0000

And the graph for the following data passes through given points is shown below:

DISCUSSION:
MATLAB has successfully been used in this assignment to interpolate data by
using Newton polynomial .

You might also like