function theResult = chi_square(x2, v)

% chi_square -- Chi-square distribution.
%  chi_square(x2, v) integrates the chi-square probability
%   density function for statistic x2, assuming v
%   degrees-of-freedom.  The integration is from zero
%   to x2.  See Press, et al., "Numerical Recipes",
%   formula (6.2.17), 1986.
 
% Copyright (C) 1999 Dr. Charles R. Denham, ZYDECO.
%  All Rights Reserved.
%   Disclosure without explicit written consent from the
%    copyright owner does not constitute publication.
 
% Version of 20-Jan-1999 11:21:31.

if nargout > 0, theResult = []; end

if nargin < 2, help(mfilename), return, end

if ischar(x2), x2 = eval(x2); end
if ischar(v), v = eval(v); end

result = gammainc(x2/2, v/2);

if nargout > 0
	theResult = result;
else
	disp(result)
end
