(* Mathematica program to print finite difference apprximation table *)
(* approximation of derivative of sin(x) using different step size *)
(* Nasser M. Abbasi, oct 2, 2010 *)

h={0.1,0.05,0.01,0.005,0.001};
exact=Cos[1];
derivativeRight=(Sin[1.0 +Δ]-Sin[1.0 ])/Δ;
derivativeLeft=(Sin[1.0]-Sin[1.0-Δ])/Δ;
derivativeCenter=(Sin[1.0 +Δ]-Sin[1.0 -Δ])/(2.0*Δ);
derivative3rdOrder=(2.0*Sin[1.0 +Δ]+3.0*Sin[1.0]-6.0*Sin[1.0-Δ]+Sin[1.0-2.0 *Δ])/(6.0*Δ);

data=Table[{h[[i]],
(derivativeRight/.Δ->h[[i]])-exact,
(derivativeLeft/.Δ->h[[i]])-exact,
(derivativeCenter/.Δ->h[[i]])-exact,
(derivative3rdOrder/.Δ->h[[i]])-exact},{i,1,Length[h]}
];

ScientificForm[TableForm[SetPrecision[data,MachinePrecision],TableHeadings->{None,{"h","D+","D","D0","D3"
}},TableAlignments->Left
],5,NumberFormat->(Row[{#1,"e",#3}]&)]