clear all exact_value=cos(0)-cos(1); % The standard indexing and h is as in the code. % while the textbook uses "Double of standard indicators" % and " h' = half of the standard h" for n=[32 64 128] h=1/n; xc_h=[0+0.5*h:h:1-0.5*h]; y_h=sin(xc_h); midp_h = h*sum(y_h); hh=2*h; xc_2h=[0+0.5*hh:hh:1-0.5*hh]; y_2h=sin(xc_2h); midp_2h = hh*sum(y_2h); p1=log2((exact_value-midp_2h)/(exact_value-midp_h)); fprintf('n = %4d , h= % 1.7f , p1 = %1.7f\n',n,h,p1) end