function arclength_x_test ( )

%*****************************************************************************80
%
%% arclength_x_test() tests arclength_x().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 November 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'arclength_x_test():\n' );
  fprintf ( 1, '  arclength_x() estimates the arclength of a curve (x,y(x))\n' );
  fprintf ( 1, '  over a range x1 <= x <= x2 using n intervals.\n' );

  x1 = 1.0;
  x2 = 4.0;
  dydx = @ dydx1;
  n = 2;

  s_true = 14.0 / 3.0;

  fprintf ( 1, '\n' );
  fprintf ( 1, '   n    s        |error|\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 5
    s = arclength_x ( x1, x2, dydx, n );
    e = abs ( s - s_true );
    fprintf ( 1, '  %2d  %8.6f  %8.6f\n', n, s, e )
    n = n * 2;
  end

  x1 = 0.0;
  x2 = 1.0;
  dydx = @ dydx2;
  n = 2;

  s_true = ( 8.0 / 27.0 ) * ( sqrt ( ( 13.0 / 4.0 )^3 ) - 1.0 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '   n    s        |error|\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 5
    s = arclength_x ( x1, x2, dydx, n );
    e = abs ( s - s_true );
    fprintf ( 1, '  %2d  %8.6f  %8.6f\n', n, s, e )
    n = n * 2;
  end

  return
end
function value = dydx1 ( x )

%*****************************************************************************80
%
%% dydx1 returns the derivative of test function 1.
%
%  Discussion:
%
%    y(x) = 2/3 ( x - 1 )^(3/2)
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X: the argument.
%
%  Output:
%
%    real VALUE: the derivative value at X.
%
  value = sqrt ( x - 1.0 );

  return
end
function value = dydx2 ( x )

%*****************************************************************************80
%
%% dydx2 returns the derivative of test function 2.
%
%  Discussion:
%
%    y(x) = x^(3/2)
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 November 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X: the argument.
%
%  Output:
%
%    real VALUE: the derivative value at X.
%
  value = 1.5 * sqrt ( x );

  return
end


