]> Creatis software - CreaPhase.git/blob - octave_packages/statistics-1.1.3/vmpdf.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / statistics-1.1.3 / vmpdf.m
1 ## Copyright (C) 2009 Soren Hauberg <soren@hauberg.org>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} @var{theta} = vmpdf (@var{x}, @var{mu}, @var{k})
18 ## Evaluates the Von Mises probability density function.
19 ##
20 ## The Von Mises distribution has probability density function
21 ## @example
22 ## f (@var{x}) = exp (@var{k} * cos (@var{x} - @var{mu})) / @var{Z} ,
23 ## @end example
24 ## where @var{Z} is a normalisation constant. By default, @var{mu} is 0 and
25 ## @var{k} is 1.
26 ## @seealso{vmrnd}
27 ## @end deftypefn
28
29 function p = vmpdf (x, mu = 0, k = 1)
30   ## Check input
31   if (!isreal (x))
32     error ("vmpdf: first input must be real");
33   endif
34   
35   if (!isreal (mu))
36     error ("vmpdf: second input must be a scalar");
37   endif
38   
39   if (!isreal (k) || k <= 0)
40     error ("vmpdf: third input must be a real positive scalar");
41   endif
42   
43   ## Evaluate PDF
44   Z = 2 * pi * besseli (0, k);
45   p = exp (k * cos (x-mu)) / Z;
46 endfunction