comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function x = chi2inv(p,v);
2 %CHI2INV Inverse of the chi-square cumulative distribution function (cdf).
3 % X = CHI2INV(P,V) returns the inverse of the chi-square cdf with V
4 % degrees of freedom at the values in P. The chi-square cdf with V
5 % degrees of freedom, is the gamma cdf with parameters V/2 and 2.
6 %
7 % The size of X is the common size of P and V. A scalar input
8 % functions as a constant matrix of the same size as the other input.
9
10 % References:
11 % [1] M. Abramowitz and I. A. Stegun, "Handbook of Mathematical
12 % Functions", Government Printing Office, 1964, 26.4.
13 % [2] E. Kreyszig, "Introductory Mathematical Statistics",
14 % John Wiley, 1970, section 10.2 (page 144)
15
16 % Copyright 1993-2002 The MathWorks, Inc.
17 % $Revision: 1.1.1.1 $ $Date: 2005/04/26 02:30:30 $
18
19 if nargin < 2,
20 error('Requires two input arguments.');
21 end
22
23 [errorcode p v] = distchck(2,p,v);
24
25 if errorcode > 0
26 error('Requires non-scalar arguments to match in size.');
27 end
28
29 % Call the gamma inverse function.
30 x = gaminv(p,v/2,2);
31
32 % Return NaN if the degrees of freedom is not positive.
33 k = (v <= 0);
34 if any(k(:))
35 x(k) = NaN;
36 end