annotate toolboxes/FullBNT-1.0.7/KPMtools/chi2inv.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function x = chi2inv(p,v);
Daniel@0 2 %CHI2INV Inverse of the chi-square cumulative distribution function (cdf).
Daniel@0 3 % X = CHI2INV(P,V) returns the inverse of the chi-square cdf with V
Daniel@0 4 % degrees of freedom at the values in P. The chi-square cdf with V
Daniel@0 5 % degrees of freedom, is the gamma cdf with parameters V/2 and 2.
Daniel@0 6 %
Daniel@0 7 % The size of X is the common size of P and V. A scalar input
Daniel@0 8 % functions as a constant matrix of the same size as the other input.
Daniel@0 9
Daniel@0 10 % References:
Daniel@0 11 % [1] M. Abramowitz and I. A. Stegun, "Handbook of Mathematical
Daniel@0 12 % Functions", Government Printing Office, 1964, 26.4.
Daniel@0 13 % [2] E. Kreyszig, "Introductory Mathematical Statistics",
Daniel@0 14 % John Wiley, 1970, section 10.2 (page 144)
Daniel@0 15
Daniel@0 16 % Copyright 1993-2002 The MathWorks, Inc.
Daniel@0 17 % $Revision: 1.1.1.1 $ $Date: 2005/04/26 02:30:30 $
Daniel@0 18
Daniel@0 19 if nargin < 2,
Daniel@0 20 error('Requires two input arguments.');
Daniel@0 21 end
Daniel@0 22
Daniel@0 23 [errorcode p v] = distchck(2,p,v);
Daniel@0 24
Daniel@0 25 if errorcode > 0
Daniel@0 26 error('Requires non-scalar arguments to match in size.');
Daniel@0 27 end
Daniel@0 28
Daniel@0 29 % Call the gamma inverse function.
Daniel@0 30 x = gaminv(p,v/2,2);
Daniel@0 31
Daniel@0 32 % Return NaN if the degrees of freedom is not positive.
Daniel@0 33 k = (v <= 0);
Daniel@0 34 if any(k(:))
Daniel@0 35 x(k) = NaN;
Daniel@0 36 end