Newtons Interpolation
Newtons Interpolation
clc;
clear all;
X = input('Enter the data points--');
Y = input('Enter the values of corresponding values--');
Xr = input('Enter the point at which value is to be calculated--');
z = size(X);
n = z(2);
T=Y;
K=Y;
Q= (X(1,1)+X(1,n))/2
if Xr<Q
%Forward Difference Table
for i=2:n
for j=1:n+1-i
T(i,j)= T(i-1,j+1) - T(i-1,j);
end
end
disp('Forward difference Table is--')
T
%Calculating FXr By Forward Difference Table
h = X(1,2)-X(1,1);
r = (Xr - X(1,1))/ h;
FXr = Y(1,1);
for i=1:n-1
p=1;
for j=1:i
p= p * (r+1-j)/j;
end
FXr = FXr + p * T(i+1,1);
end
disp('The value at point is--')
FXr
else
%Backward Difference Table
for p=2:n
for q=n:-1:p
K(p,q)= K(p-1,q) - K(p-1,q-1);
end
end
disp('Backward difference Table is--')
K
%Calculating FXr By Backward Difference Table
h = X(1,2)-X(1,1);
r = (Xr - X(1,n))/ h;
FXr = Y(1,n);
for i=1:n-1
b=1;
for j=1:i
b= b * (r-1+j)/j;
end
FXr = FXr + b * K(i+1,n);
end
disp('The value at point is--')
FXr
end