]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/tcdf.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / tcdf.m
1 function p = tcdf(x,n)
2 % TCDF returns student cumulative distribtion function
3 %
4 % cdf = tcdf(x,DF);
5 %
6 % Computes the CDF of the students distribution 
7 %    with DF degrees of freedom 
8 % x,DF must be matrices of same size, or any one can be a scalar. 
9 %
10 % see also: NORMCDF, TPDF, TINV 
11
12 % Reference(s):
13
14 %       $Id: tcdf.m 9033 2011-11-08 20:58:07Z schloegl $
15 %       Copyright (C) 2000-2003,2009 by Alois Schloegl <alois.schloegl@gmail.com>       
16 %       This is part of the NaN-toolbox. For more details see
17 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
18
19 %    This program is free software; you can redistribute it and/or modify
20 %    it under the terms of the GNU General Public License as published by
21 %    the Free Software Foundation; either version 3 of the License, or
22 %    (at your option) any later version.
23 %
24 %    This program is distributed in the hope that it will be useful,
25 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
26 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 %    GNU General Public License for more details.
28 %
29 %    You should have received a copy of the GNU General Public License
30 %    along with this program; If not, see <http://www.gnu.org/licenses/>.
31
32
33 % check size of arguments
34 if all(size(x)==1)
35         x = repmat(x,size(n));
36 elseif all(size(n)==1)
37         n = repmat(n,size(x));
38 elseif all(size(x)==size(n))
39         ;       %% OK, do nothing
40 else
41         error('size of input arguments must be equal or scalar')
42 end;    
43                 
44 % allocate memory
45 p = zeros(size(x));
46 p((x==Inf) & (n>0)) = 1;
47
48 % workaround for invalid arguments in BETAINC
49 ix   = isnan(x) | ~(n>0);
50 p(ix)= NaN;
51
52 ix    = (x > -Inf) & (x < Inf) & (n > 0);
53 p(ix) = betainc (n(ix) ./ (n(ix) + x(ix).^2), n(ix)/2, 1/2) / 2;
54
55 ix    = find(x>0);
56 p(ix) = 1 - p(ix);
57
58 % shape output
59 p = reshape(p,size(x));
60
61 %!assert(tcdf(NaN,4),NaN)