]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/tpdf.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / tpdf.m
1 function p = tpdf(x,n)
2 % TPDF returns student probability density 
3 %
4 % pdf = tpdf(x,DF);
5 %
6 % Computes the PDF of a the student distribution 
7 %    with DF degreas of freedom
8 % x,DF must be matrices of same size, or any one can be a scalar. 
9 %
10 % see also: TINV, TCDF, NORMPDF, NORMCDF, NORMINV 
11
12 % Reference(s):
13
14 %       $Id: tpdf.m 9033 2011-11-08 20:58:07Z schloegl $
15 %       Copyright (C) 2000-2003,2008,2009,2010 by Alois Schloegl <alois.schloegl@gmail.com>     
16 %       This function is part of the NaN-toolbox
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 2 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 % allocate memory and check size of arguments
33 p = x+n;          % if this line causes an error, size of input arguments do not fit. 
34 ix = (n>0) & (n~=inf) & ~isnan(x); 
35
36 % make size of x and n equal
37 n = x+n-x;
38 x = x+n-n;
39
40 % workaround for invalid arguments in BETA
41 if any(ix)
42 p(ix) = (exp (-(n(ix)+1).*log(1+x(ix).^2./n(ix))/2) ./ (sqrt(n(ix)).* beta(n(ix)/2, 1/2)));
43 end; 
44 p(~ix)= NaN;
45
46 % shape output
47 p = reshape(p,size(x));
48
49 %!assert(tpdf(NaN,4),NaN)