Newton[n_,x0_,h_,f_]:=Block[{i,q,poly,node,g},Do[node[i-1]=x0+h*(i-1);
g[i-1]=f[node[i-1]],{i,n}];
g[i_,0]:=g[i];
g[q_,i_]:=(g[q,i-1]-g[q-1,i-1])/(node[q]-node[q-i])/;i>0;
N[Sum[g[i,i]*Product[(x-node[j-1]),{j,1,i}],{i,0,n-1}]]];
g[x_]:=E^x;

t[x_]=Newton[5,0,1,g];

t[3]

t[4]

Plot[{t[x],E^x,},{x,0,5}]

NewtonBackwards[n_,x0_,h_,f_]:=Block[{i,k,node,g,zx},
Do[node[i]=x0+h*i;g[i]=f[node[i]],{i,0,n-1}];
g[0,i_]:=g[i];
g[k_,i_]:=(g[k-1,i+1]-g[k-1,i])/;k>0;
zx=0;
Do[zx=zx+Binomial[(x-(x0+h*(n-1)))/h,i]*g[i,n-i-1],{i,0,n-1}];Expand[N[zx]]];

(*ne mojah da dovursha funkciqta, smqta vqrno samo posledniq chlen*)

c[x_]=E^x;

NewtonBackwards[5,0,1,c]

Plot[{1392.399820510397` -1110.1274295786868` x+331.83773569849234` (x^2)-44.29620201205611` (x^3)+2.274922918047676` (x^4),E^x},{x,0,4}]

g[x]

NewtonBack[n_,x0_,h_,f_]:=Block[{i,k,node,zx,m,p},
f2[l_]:=f[x0+l*h];
DivDiff[k_,p_]:=Sum[(-1)^m*Binomial[k,m]*f2[p-m],{m,0,k}];
Poly=f2[n]+Sum[(-1)^k*Binomial[-(x-x0-n*h)/h,k]*DivDiff[k,0]*f2[n],{k,1,n}]; 
Expand[N[Poly]]
];

zt[x_]=NewtonBack[5,0,1,g]
zt[x]

polzz[x_]:=Expand[N[InterpolatingPolynomial[{{0,1},{1,E},{2,E^2},{3,E^3},{4,E^4},{5,E^5}},x]]]
polzz[x]

Plot[{polzz[x],zt[x],g[x]},{x,0,5}]

Binomial[x+2,3]

nback[n_,x0_,h_,f_]:=Block[{l,k,node,m,Poly,f2,Q},
f2[l_]:=f[x0+l*h];
node[l_]:=x0+l*h;
DivDiff[k_,p_]:=Sum[(-1)^m*Binomial[k,m]*f2[p-m],{m,0,k}];
Q[k_,x_]=Product[x-node[n-j],{j,0,k-1}];
Poly=f2[n]+Sum[DivDiff[k,0]*f2[n]/(k!*h^k)*Q[k,x],{k,1,n}];
Expand[N[Poly]]
];

nback[5,0,1,g]

polzz[x]

NewtonBackRec[n_,x0_,h_,f_]:=Block[{i,k,node,zx,m,p},
f2[l_]:=f[x0+l*h];
DivDiff[0,p_]:=f2[p];
DivDiff[k_,p_]:=(DivDiff[k-1,p]-DivDiff[k-1,p-1])/;k>0;
Poly=f2[n]+Sum[(-1)^k*Binomial[-(x-x0-n*h)/h,k]*DivDiff[k,0]*f2[n],{k,1,n}]; 
Expand[N[Poly]]
];

g[x_]:=4x^2+3;

nback[6,0,1,g]

-621.`+108.` x

nback[5,0,1,g]