changelog shortlog tags changeset files revisions annotate raw

scripts/statistics/distributions/wblpdf.m

changeset 10289: 4b124317dc38
parent:f0c3d3fc4903
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (57 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 1995, 1996, 1997, 2006, 2007, 2009 Kurt Hornik
2##
3## This file is part of Octave.
4##
5## Octave is free software; you can redistribute it and/or modify it
6## under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 3 of the License, or (at
8## your option) any later version.
9##
10## Octave is distributed in the hope that it will be useful, but
11## WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13## General Public License for more details.
14##
15## You should have received a copy of the GNU General Public License
16## along with Octave; see the file COPYING. If not, see
17## <http://www.gnu.org/licenses/>.
18
19## -*- texinfo -*-
20## @deftypefn {Function File} {} wblpdf (@var{x}, @var{scale}, @var{shape})
21## Compute the probability density function (PDF) at @var{x} of the
22## Weibull distribution with shape parameter @var{scale} and scale
23## parameter @var{shape} which is given by
24##
25## @tex
26## $$ scale \cdot shape^{-scale} x^{scale-1} \exp(-(x/shape)^{scale}) $$
27## @end tex
28## @ifnottex
29## @example
30## scale * shape^(-scale) * x^(scale-1) * exp(-(x/shape)^scale)
31## @end example
32## @end ifnottex
33##
34## @noindent
35## for @var{x} > 0.
36## @end deftypefn
37
38## Author: KH <Kurt.Hornik@wu-wien.ac.at>
39## Description: PDF of the Weibull distribution
40
41function pdf = wblpdf (x, scale, shape)
42
43 if (nargin < 1 || nargin > 3)
44 print_usage ();
45 endif
46
47 if (nargin < 3)
48 shape = 1;
49 endif
50
51 if (nargin < 2)
52 scale = 1;
53 endif
54
55 if (!isscalar (shape) || !isscalar (scale))
56 [retval, x, shape, scale] = common_size (x, shape, scale);
57 if (retval > 0)
58 error ("wblpdf: x, scale and shape must be of common size or scalar");
59 endif
60 endif
61
62 pdf = NaN * ones (size (x));
63 ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf));
64
65 k = find ((x > -Inf) & (x <= 0) & ok);
66 if (any (k))
67 pdf(k) = 0;
68 endif
69
70 k = find ((x > 0) & (x < Inf) & ok);
71 if (any (k))
72 if (isscalar (shape) && isscalar (scale))
73 pdf(k) = (shape .* (scale .^ -shape)
74 .* (x(k) .^ (shape - 1))
75 .* exp(- (x(k) / scale) .^ shape));
76 else
77 pdf(k) = (shape(k) .* (scale(k) .^ -shape(k))
78 .* (x(k) .^ (shape(k) - 1))
79 .* exp(- (x(k) ./ scale(k)) .^ shape(k)));
80 endif
81 endif
82
83endfunction