Finding expected value by backward method by mathematica - interpolation

By mathematica:



Module[{n=Input["How many data"]},
Do[x[i]=Input["Enter the value of x"];
y[i][1]=Input["Enter the value of corresponding y"],{i,1,n}];
xo=Input["For what value of x you want the value of y"];
Do[y[i+1][j+1]=y[i+1][j]-y[i][j],{i,1,n-1},{j,1,i}];
Print["The table of difference is : "];
Print[TableForm[Table[PaddedForm[y[i][j],{12,8}],{i,1,n},{j,1,i}]]];
ans=y[n][1];
h=x[2]-x[1];
p=(xo-x[n])/h;
extra=1;
Do[extra=extra*(p+(i-1));
ans=ans+(extra*y[n][i+1])/Factorial[i],{i,1,n-1}];
Print["Rcquired result is : ",PaddedForm[ans//N,{12,8}]]];

Related Posts
Previous
« Prev Post