function driverf (fname, a, b, Itrue);
% function driverf (fname, a, b, Itrue);
% driverf.m computes and outputs the table for n, Iapprox, error, and ratio
% for an integral \int_a^b f(x) \, dx, where a and b are input and f(x)
% is contained in m-file fname.m. Here, Itrue is the true value of the integral
% used in the computations; if missing, Matlab's quad8 function is used
% to approximate Itrue to high order.

  if (nargin < 5), Itrue = quad8 (fname, a, b); end;

  % ... output table headers:
  fprintf (1, ['    n        Iapprox               error    ratio\n']);

  n = 2;
  Iapprox = simpson (fname, a, b, n);
  error = Itrue - Iapprox;
  fprintf (1, '%5d %22.15f %12.2e      \n', n, Iapprox, error);

  for i = 2 : 9
    n = 2^i;
    Iapprox = simpson (fname, a, b, n);
    errorold = error;
    error = Itrue - Iapprox;
    ratio = errorold / error;
    fprintf (1, '%5d %22.15f %12.2e %7.2f\n', n, Iapprox, error, ratio);
  end;

