function value = elliptic_ea ( a )

%*****************************************************************************80
%
%% elliptic_ea() evaluates the complete elliptic integral E(A).
%
%  Discussion:
%
%    The value is computed using Carlson elliptic integrals:
%
%      E(a) = RF ( 0, 1-sin^2(a), 1 ) - 1/3 sin^2(a) RD ( 0, 1-sin^2(a), 1 ).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 June 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real A, the argument.
%
%  Output:
%
%    real VALUE, the function value.
%
  k = sin ( a * pi / 180.0 );

  x = 0.0;
  y = ( 1.0 - k ) * ( 1.0 + k );
  z = 1.0;
  errtol = 1.0E-03;

  [ value1, ierr ] = rf ( x, y, z, errtol );
  if ( ierr ~= 0 )
    fprintf ( 1, 'ELLIPTIC_EA - Fatal error!\n' );
    fprintf ( 1, '  RF returned IERR = %d\n', ierr );
    error ( 'ELLIPTIC_EA - Fatal error!' );
    return
  end

  [ value2, ierr ] = rd ( x, y, z, errtol );
  if ( ierr ~= 0 )
    fprintf ( 1, 'ELLIPTIC_EA - Fatal error!\n' );
    fprintf ( 1, '  RD returned IERR = %d\n', ierr );
    error ( 'ELLIPTIC_EA - Fatal error!' );
    return
  end

  value = value1 - k * k * value2 / 3.0;

  return
end
