Programme
function fx = backward(x, y, b)
clc;
x = input('Enter the Value of x in Vector form:')
y = input('Enter the Value of y in Vector form:')
b = input('Enter the Point to be Interpolated:')
n = length(x);
format long
%Now we wrte the code for difference table
for i = 1:n-1%assigns value of row
del(i,1) = y(i+1) - y(i);%We find first difference table column
end
for k = 2:n-1%assigns value of column
for i = 1:n-k%finds second to nth difference table columns
del(i,k) = del(i+1,k-1) - del(i,k-1);
end
end
del
h =x(2) - x(1);
%Code of newton forward formula coefficient loop
p = (b - x(n))/h;
for j = i:(n-1)
if j==1 %NBF 2nd term
c(1) = p*del(n-1,j);
else
t=p;
for f = 1:j-1 %NBF 3,4,5th... term
t = t*(p+f);
end
c(j) = t*del(n-j,j)/factorial(j);
end
end
sum(c);
ans = y(n) + sum(c)
end
Input and Output
Enter the Value of x in Vector form:[10 15 30 35 45 60]
x=
10 15 30 35 45 60
Enter the Value of y in Vector form:[0.1736 0.2588 .5 .5735 0.7071 0.866]
y=
0.173600000000000 0.258800000000000 0.500000000000000 0.573500000000000
0.707100000000000 0.866000000000000
Enter the Point to be Interpolated:40
b=
40
del =
0.085200000000000 0.156000000000000 -0.323700000000000 0.551500000000000 -
0.814100000000000
0.241200000000000 -0.167700000000000 0.227800000000000 -0.262600000000000 0
0.073500000000000 0.060100000000000 -0.034800000000000 0 0
0.133600000000000 0.025300000000000 0 0 0
0.158900000000000 0 0 0 0
Enter Value of n:
Enter Value of n:
ans =
0.866000000000000