Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/KPMtools/chi2inv.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function x = chi2inv(p,v); |
wolffd@0 | 2 %CHI2INV Inverse of the chi-square cumulative distribution function (cdf). |
wolffd@0 | 3 % X = CHI2INV(P,V) returns the inverse of the chi-square cdf with V |
wolffd@0 | 4 % degrees of freedom at the values in P. The chi-square cdf with V |
wolffd@0 | 5 % degrees of freedom, is the gamma cdf with parameters V/2 and 2. |
wolffd@0 | 6 % |
wolffd@0 | 7 % The size of X is the common size of P and V. A scalar input |
wolffd@0 | 8 % functions as a constant matrix of the same size as the other input. |
wolffd@0 | 9 |
wolffd@0 | 10 % References: |
wolffd@0 | 11 % [1] M. Abramowitz and I. A. Stegun, "Handbook of Mathematical |
wolffd@0 | 12 % Functions", Government Printing Office, 1964, 26.4. |
wolffd@0 | 13 % [2] E. Kreyszig, "Introductory Mathematical Statistics", |
wolffd@0 | 14 % John Wiley, 1970, section 10.2 (page 144) |
wolffd@0 | 15 |
wolffd@0 | 16 % Copyright 1993-2002 The MathWorks, Inc. |
wolffd@0 | 17 % $Revision: 1.1.1.1 $ $Date: 2005/04/26 02:30:30 $ |
wolffd@0 | 18 |
wolffd@0 | 19 if nargin < 2, |
wolffd@0 | 20 error('Requires two input arguments.'); |
wolffd@0 | 21 end |
wolffd@0 | 22 |
wolffd@0 | 23 [errorcode p v] = distchck(2,p,v); |
wolffd@0 | 24 |
wolffd@0 | 25 if errorcode > 0 |
wolffd@0 | 26 error('Requires non-scalar arguments to match in size.'); |
wolffd@0 | 27 end |
wolffd@0 | 28 |
wolffd@0 | 29 % Call the gamma inverse function. |
wolffd@0 | 30 x = gaminv(p,v/2,2); |
wolffd@0 | 31 |
wolffd@0 | 32 % Return NaN if the degrees of freedom is not positive. |
wolffd@0 | 33 k = (v <= 0); |
wolffd@0 | 34 if any(k(:)) |
wolffd@0 | 35 x(k) = NaN; |
wolffd@0 | 36 end |