%% t2_minus_t1
%
%  Discussion:
%
%    Compare exact error to estimate t2-t1.
%
fprintf ( 1, '\n' );
fprintf ( 1, 't2_minus_t1:\n' );
fprintf ( 1, '  Estimate quadrature error in T1(f,a,b)\n' );
fprintf ( 1, '  by subtracting from T2(f,a,b).\n' );
fprintf ( 1, '\n' );
fprintf ( 1, '  a       b         E1           e1         E2          e2\n' );
fprintf ( 1, '\n' );
for j = 1 : 10
  a = ( j - 1 ) / 10;
  b = 2 * j / 10;
  i = i_exact ( a, b );
  h = b - a;
  ab = ( a + b ) / 2.0;
  fave1 = ( 0.5 * f(a) + 0.5 * f(b) );
  fave2 = ( 0.25 * f(a) + 0.5 * f(ab) + 0.25 * f(b) );
  q1 = h * fave1;
  q2 = h * fave2;
  E1 = i - q1;
  E2 = i - q2;
  e1 = 4 * ( q2 - q1 ) / 3.0;
  e2 =     ( q2 - q1 ) / 3.0;
  r1 = e1 / E1;
  r2 = e2 / E2;

  fprintf ( 1, '%6.2f  %6.2f  %10.6f  %10.6f  %10.6f  %10.6f\n', ...
    a, b, E1, e1, E2, e2 );

end

fprintf ( 1, '\n' );
fprintf ( 1, '  Normal end of execution.\n' );

function value = f(x)
  value = exp ( x );
  return
end
function value = i_exact ( a, b )
  value = exp(b) - exp(a);
  return
end

