Date post: | 25-Dec-2015 |
Category: |
Documents |
Upload: | tahsin-mostafiz |
View: | 216 times |
Download: | 4 times |
Course No.: EEE 212 Group No.:06
Course Title: Numerical Technique Laboratory
Name of the Assignment:
Name: Md. Tahsin Mostafiz
Student ID: 201106109
Department: EEE
Level:2 Term: 2
Partner Student’s ID: 2011061110
EXPLANATION OF THE ALGORITHM OF NEWTON’S INTERPOLATION. GENERATION OF A SMOOTH CURVE FOR SOME GIVEN DATA POINTS, USING NEWTON'S INTERPOLATION.
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,1…n : 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,1…n :
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 x’s
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 .