annotate scripts/statistics/distributions/lognpdf.m @ 11472:1740012184f9

Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
author Rik <octave@nomad.inbox5.com>
date Sun, 09 Jan 2011 21:33:04 -0800
parents a1dbe9d80eee
children fd0a3ac60b0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 Kurt Hornik
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
2 ##
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
4 ##
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6617
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6617
diff changeset
8 ## your option) any later version.
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
9 ##
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
14 ##
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6617
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6617
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
18
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
20 ## @deftypefn {Function File} {} lognpdf (@var{x}, @var{mu}, @var{sigma})
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
21 ## For each element of @var{x}, compute the probability density function
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
22 ## (PDF) at @var{x} of the lognormal distribution with parameters
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
23 ## @var{mu} and @var{sigma}. If a random variable follows this distribution,
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
24 ## its logarithm is normally distributed with mean @var{mu}
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
25 ## and standard deviation @var{sigma}.
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
26 ##
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
27 ## Default values are @var{mu} = 1, @var{sigma} = 1.
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
28 ## @end deftypefn
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
29
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5411
diff changeset
30 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
31 ## Description: PDF of the log normal distribution
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
32
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
33 function pdf = lognpdf (x, mu, sigma)
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
34
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
35 if (! ((nargin == 1) || (nargin == 3)))
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5692
diff changeset
36 print_usage ();
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
37 endif
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
38
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
39 if (nargin == 1)
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
40 mu = 0;
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
41 sigma = 1;
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
42 endif
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
43
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
44 ## The following "straightforward" implementation unfortunately does
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
45 ## not work for the special cases (Inf, ...)
6617
55da54f6c5c2 [project @ 2007-05-14 16:17:46 by jwe]
jwe
parents: 6046
diff changeset
46 ## pdf = (x > 0) ./ x .* normpdf (log (x), mu, sigma);
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
47 ## Hence ...
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
48
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
49 if (!isscalar (mu) || !isscalar (sigma))
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
50 [retval, x, mu, sigma] = common_size (x, mu, sigma);
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
51 if (retval > 0)
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
52 error ("lognpdf: X, MU and SIGMA must be of common size or scalars");
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
53 endif
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
54 endif
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
55
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
56 pdf = zeros (size (x));
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
57
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
58 k = find (isnan (x) | !(sigma > 0) | !(sigma < Inf));
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
59 if (any (k))
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
60 pdf(k) = NaN;
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
61 endif
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
62
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
63 k = find ((x > 0) & (x < Inf) & (sigma > 0) & (sigma < Inf));
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
64 if (any (k))
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
65 if (isscalar (mu) && isscalar (sigma))
6617
55da54f6c5c2 [project @ 2007-05-14 16:17:46 by jwe]
jwe
parents: 6046
diff changeset
66 pdf(k) = normpdf (log (x(k)), mu, sigma) ./ x(k);
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
67 else
6617
55da54f6c5c2 [project @ 2007-05-14 16:17:46 by jwe]
jwe
parents: 6046
diff changeset
68 pdf(k) = normpdf (log (x(k)), mu(k), sigma(k)) ./ x(k);
5692
fe226f54d259 [project @ 2006-03-17 17:02:32 by jwe]
jwe
parents: 5428
diff changeset
69 endif
5410
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
70 endif
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
71
56e066f5efc1 [project @ 2005-07-13 17:43:35 by jwe]
jwe
parents:
diff changeset
72 endfunction