function y = x2cdf(x,k) % Evaluates the cumulative distribution function of the chi-square % distribution at x with k df. alpha = k/2; beta = 2; a = zeros(alpha,1); for ii = 0:alpha-1 if ii == 0 a(ii+1) = (x/beta)^ii; else a(ii+1) = (x/beta)^ii / prod(1:ii); end end y = 1 - exp(-x/beta) * sum(a);