function s = arclength_x ( x1, x2, dydx, n )

%*****************************************************************************80
%
%% arclength_x estimates arclength for a curve of the form (x,f(x)).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real x1, x2: the range over which the curve extends.
%
%    function handle dydx: a function which evaluates dy/dx.
%
%    integer n: the number of intervals to use.
%
%  Output:
%
%    real s: the estimated arclength.
%
  dx = ( x2 - x1 ) / n;

  x = linspace ( x1, x2, n + 1 );
  dy = dydx ( x );

  s = dx * ( sum ( sqrt ( 1.0 + dy.^2 ) ) ...
    - 0.5 * sqrt ( 1.0 + dy(1)^2 ) ...
    - 0.5 * sqrt ( 1.0 + dy(n+1)^2 ) );

  return
end

