
%  Program "First" from Cheney-Kincaid
%  Approximation of the first derivative of f(x)= sin(x)
%  at x=0.5 using forward differences.
%  The purpose is to show that a loss precision
%  may results by subtracting nearly equal numbers in a computer.

format short e;
N=30;
x=0.5;
h=1.;

for i=1:N
    h=.25*h;
    y=(sin(x+h)-sin(x))/h;
    error=abs(cos(x)-y);
    disp([i,h,y,error]);
end



