% Q11 Page50 Section 2.2 i = [1:14] ; hinv = 2.^i ; h = hinv.^(-1) ; x = pi/4 ; val = 1/(1+x^2) ; f1x = (8*atan(x+h)-8*atan(x-h)-atan(x+2*h)+atan(x-2*h))./(12*h) ; error = abs(f1x-val) ; semilogy(hinv,error) ; xlabel('h inverse') ; ylabel('log error') ; minError = min(error) ; indexME = find(minError == error) fprintf('The power of 2 is -%d or The value of h for minimum eror is 1/%d',indexME,2^(indexME)) ;
indexME =
11
The power of 2 is -11 or The value of h for minimum eror is 1/2048