function eoc = convergence_n ( n, e )

%*****************************************************************************80
%
%% convergence() estimates the n-based order of convergence.
%
%  Discussion:
%
%    We assume that the exact solution of a problem is known, and that 
%    nn successive approximations to this solution have been made.
%    The order (number of intervals or nodes) used in the k-th approximation 
%    is n(k).
%    The absolute error in the k-th approximation is given as e(k).
%    This code estimates the order of convergence using successive
%    pairs of errors:
%      eoc(k) = log ( e(k-1) / e(k) ) / log ( n(k) / n(k-1) ).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 September 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real n(nn): the number of nodes or intervals used at each step.
%    Typically, the next value is twice the previous one.
%
%    real e(nn): the error for each value of n.  These must be strictly
%    positive, nonzero values.
%
%  Output:
%
%    real eoc(nn): the estimates for convergence order.  eoc(1) is not
%    defined, and is returned as NaN.
%
  nn = length ( e );

  eoc = zeros(1,nn);

  for k = 1 : nn
    if ( k == 1 )
      eoc(k) = NaN;
    else
      eoc(k) = log ( e(k-1) / e(k) ) / log ( n(k) / n(k-1) );
    end
  end

  return
end
