%derivtd
a=input('enter a =');
n=input('enter n =');
delta=input('enter noise level delta =');
for k=1:n
   h(k)=10^(-k);
   Dh(k)=( sin(a+h(k))-sin(a)+rand*delta )/h(k);
   err(k)=abs(Dh(k)-cos(a));
end
semilogy(1:n,err,1:n-1,abs(diff(Dh)),'.');