function [ q, e ] = cosfrac_composite ( m, n )

%% cosfrac_composite estimates integral 1/(2+cos(x)) using a composite rule.
%
  a = 0.0;
  b = 2.0 * pi;
  q = 0.0;
%
%  Divide [a,b] into m equal subintervals with endpoints s.
%
  s = linspace ( a, b, m + 1 );
%
%  For each subinterval [s(i),s(i+1)], estimate the subintegral qs.
%
  for i = 1 : m
    [ x, w ] = gauss_ab ( n, s(i), s(i+1) );
    qs = w' * cosfrac ( x );
    q = q + qs;
  end

  e = cosfrac_int() - q;

  return
end
function value = cosfrac ( x )
  value = 1.0 ./ ( 2.0 + cos ( x ) );
  return
end

function value = cosfrac_int ( )
  value = 3.62759872846844;
  return
end

