wolffd@0: function x = chi2inv(p,v); wolffd@0: %CHI2INV Inverse of the chi-square cumulative distribution function (cdf). wolffd@0: % X = CHI2INV(P,V) returns the inverse of the chi-square cdf with V wolffd@0: % degrees of freedom at the values in P. The chi-square cdf with V wolffd@0: % degrees of freedom, is the gamma cdf with parameters V/2 and 2. wolffd@0: % wolffd@0: % The size of X is the common size of P and V. A scalar input wolffd@0: % functions as a constant matrix of the same size as the other input. wolffd@0: wolffd@0: % References: wolffd@0: % [1] M. Abramowitz and I. A. Stegun, "Handbook of Mathematical wolffd@0: % Functions", Government Printing Office, 1964, 26.4. wolffd@0: % [2] E. Kreyszig, "Introductory Mathematical Statistics", wolffd@0: % John Wiley, 1970, section 10.2 (page 144) wolffd@0: wolffd@0: % Copyright 1993-2002 The MathWorks, Inc. wolffd@0: % $Revision: 1.1.1.1 $ $Date: 2005/04/26 02:30:30 $ wolffd@0: wolffd@0: if nargin < 2, wolffd@0: error('Requires two input arguments.'); wolffd@0: end wolffd@0: wolffd@0: [errorcode p v] = distchck(2,p,v); wolffd@0: wolffd@0: if errorcode > 0 wolffd@0: error('Requires non-scalar arguments to match in size.'); wolffd@0: end wolffd@0: wolffd@0: % Call the gamma inverse function. wolffd@0: x = gaminv(p,v/2,2); wolffd@0: wolffd@0: % Return NaN if the degrees of freedom is not positive. wolffd@0: k = (v <= 0); wolffd@0: if any(k(:)) wolffd@0: x(k) = NaN; wolffd@0: end