% Script deriv3.m % The derivative approximations get better for awhile % since the error in last column decreases and then % they get worse. % Eventually the derivative approximation becomes zero. % The reason is that, as h gets closed to 0, 0.5+h will % be 0.5 for some small non-zero value of h. % For this h and any smallre ones the numerator in the % calculation of the ratio r becomes exactly zero. % try 30 iterations num_iter = input('Enter number of iterations '); exact = log(1.1); fprintf('Exact value = %.10e\n', exact); fprintf('%5s %18s %18s %18s\n','n','h','r','err'); h = 1.0; for n = 1 : num_iter r = (log(1.1+h) - log(1.1)) / h; err = exact - r; fprintf('%5d %18.10e %18.10e %18.10e\n',n,h,r,err); h = h / 4.0; end