% **************************************************************
% * MATLAB FRAMEWORK CAP DISCREPANCY:                          *
% *                                                            *
% *   AUTHOR    : Holger Heitsch                               *
% *   INSTITUTE : WIAS Berlin                                  *
% *   (C)       : 2020                                         *
% *                                                            *
% **************************************************************

% **************************************************************
%
%   SPHERICAL CAP MEASURE
%
% **************************************************************

% **************************************************************
%
%   Computing the spherical cap measure
%
%   Input: n - space dimension
%          t - shift of hyperplane in [-1,1]
%
%   Return:   cap - cap measure
%           c_cap - complementary cap measure
%
%   Required function: betainc()
%                      (Matlab built-in function)
% 
% **************************************************************


function [cap, c_cap] = cap_measure (n, t)

    % Computing cap measure by incomplete beta function
    c = 0.5 * betainc (1 - t*t, (n-1)/2, 0.5);
    
    if (t > 0)
        cap   = c;
        c_cap = 1 - c;
    else
        cap   = 1 - c;
        c_cap = c;
    end

end

