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