Program
function[]=back(X,Y,x0)
n=length(X)
h=X(2)-X(1);
for i=1:n
Z(i)=Y(i);
d(i,1)=Y(i);
end
for i=1:n-1
for j=1:n-i
d(i,j)=Z(j+1)-Z(j);
D(j,i+1)=d(i,j);
end
for k=1:n-i
Z(k)=d(i,k);
end
d(i,n)=Z(k);
end
printf('difference table is')
disp(D)
y_x=Y(n);
p=(x0-X(n))/h;
for i=1:n-1
pp=1;
for j=1:i
pp=pp*(p+(j-1));
end
y_x=y_x+((pp*d(i,n))/factorial(i))
end
printf('value of function at %.4f is %.4f',x0,y_x)
endfunction
Output:
Warning : redefining function: back . Use funcprot(0) to avoid this message
exec('C:\Users\acer\back.sce', -1)
x=(100:50:300);
y=[958 917 865 799 712];
back(x,y,275)
difference table is
0. -41. -11. -3. -4.
0. -52. -14. -7. 0.
0. -66. -21. 0. 0.
0. -87. 0. 0. 0.
value of function at 275.0000 is 758.7188
function[]=back(X,Y,x0)
n=length(X)
h=X(2)-X(1);
for i=1:n
Z(i)=Y(i);
d(i,1)=Y(i);
end
for i=1:n-1
for j=1:n-i
d(i,j)=Z(j+1)-Z(j);
D(j,i+1)=d(i,j);
end
for k=1:n-i
Z(k)=d(i,k);
end
d(i,n)=Z(k);
end
printf('difference table is')
disp(D)
y_x=Y(n);
p=(x0-X(n))/h;
for i=1:n-1
pp=1;
for j=1:i
pp=pp*(p+(j-1));
end
y_x=y_x+((pp*d(i,n))/factorial(i))
end
printf('value of function at %.4f is %.4f',x0,y_x)
endfunction
Output:
Warning : redefining function: back . Use funcprot(0) to avoid this message
exec('C:\Users\acer\back.sce', -1)
x=(100:50:300);
y=[958 917 865 799 712];
back(x,y,275)
difference table is
0. -41. -11. -3. -4.
0. -52. -14. -7. 0.
0. -66. -21. 0. 0.
0. -87. 0. 0. 0.
value of function at 275.0000 is 758.7188
0 Comments