Program
function[]=forward(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(i,1)=d(i,j);
end
for k=1:n-i
Z(k)=d(i,k)
end
end
printf('difference table is')
disp(D)
y_x=Y(1);
p=(x0-X(1))/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,i))/factorial(i))
end
printf('value of function at %.4f is %.4f',x0,y_x)
endfunction
Output:
-->X=(100:50:300);
-->Y=[958 917 865 799 712];
-->forward(X,Y,125)
difference table is
- 87.
- 21.
- 7.
- 4.
712.
value of function at 125.0000 is 939.2500
function[]=forward(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(i,1)=d(i,j);
end
for k=1:n-i
Z(k)=d(i,k)
end
end
printf('difference table is')
disp(D)
y_x=Y(1);
p=(x0-X(1))/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,i))/factorial(i))
end
printf('value of function at %.4f is %.4f',x0,y_x)
endfunction
Output:
-->X=(100:50:300);
-->Y=[958 917 865 799 712];
-->forward(X,Y,125)
difference table is
- 87.
- 21.
- 7.
- 4.
712.
value of function at 125.0000 is 939.2500
0 Comments