Finding expected value by forward method by mathematica - interpolation

By mathematica:



Module[{n=Input["How many data"]},
Do[x[i]=Input["Enter the vlues of x"];
y[i][1]=Input["Enter the vlues of y"],{i,1,n}];
xo=Input["For what value you want the value of y"];
Do[y[n-i][j+1]=y[n-i+1][j]-y[n-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,n+1-i}]]];
ans=y[1][1];
h=x[2]-x[1];
p=(xo-x[1])/h;
extra=1;
Do[extra=extra*(p-(i-1));
ans=ans+(extra*y[1][i+1])/Factorial[i],{i,1,n-1}];
Print["Rcquired result is : ",PaddedForm[ans//N,{12,8}]]];

Related Posts
Previous
« Prev Post