Download as zip, pdf, or txt
Download as zip, pdf, or txt
You are on page 1of 2

function newtonsforward(x, y, xg)

n=length(x);
if(length(x)<>length(y)) then
disp("Not Possible");
abort;
end
h=x(2)-x(1);
p=(xg-x(1))/h;
for i=1:n-1
d(i,1)=y(i+1)-y(i);
end
for j=2:n-1
for i=1:n-j
d(i,j)=d(i+1,j-1)-d(i,j-1);
end
end
disp("The Values of x",x);
disp("The Values of y",y);
disp("Forward Difference Table",d);
term(1)=p;
for i=2:n-1
term(i)=term(i-1)*(p+1-i);
end
t=0;
for i=1:n-1
t=t+((term(i)*d(1,i))/factorial(i));
end
ye=y(1)+t;
disp("The estimated value of y is",ye);
endfunction

x=[5,10,15,20];
y=[50,70,100,145];
xg=8;
newtonsforward(x, y, xg)

Output

Startup execution:
loading initial environment

--> exec('/Users/ajaymahadevchavan/practica;l.sce', -1)

5. 10. 15. 20.

The Values of x

50. 70. 100. 145.

The Values of y

20. 10. 5.
30. 15. 0.
45. 0. 0.

Forward Difference Table

61.08

The estimated value of y is

You might also like