1 ## Copyright (C) 2006, 2007 Arno Onken <asnelt@asnelt.org>
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
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
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/>.
17 ## @deftypefn {Function File} {[@var{m}, @var{v}] =} wblstat (@var{scale}, @var{shape})
18 ## Compute mean and variance of the Weibull distribution.
20 ## @subheading Arguments
24 ## @var{scale} is the scale parameter of the Weibull distribution.
25 ## @var{scale} must be positive
28 ## @var{shape} is the shape parameter of the Weibull distribution.
29 ## @var{shape} must be positive
31 ## @var{scale} and @var{shape} must be of common size or one of them must be
34 ## @subheading Return values
38 ## @var{m} is the mean of the Weibull distribution
41 ## @var{v} is the variance of the Weibull distribution
44 ## @subheading Examples
50 ## [m, v] = wblstat (scale, shape)
54 ## [m, v] = wblstat (6, shape)
58 ## @subheading References
62 ## Wendy L. Martinez and Angel R. Martinez. @cite{Computational Statistics
63 ## Handbook with MATLAB}. Appendix E, pages 547-557, Chapman & Hall/CRC,
67 ## Athanasios Papoulis. @cite{Probability, Random Variables, and Stochastic
68 ## Processes}. McGraw-Hill, New York, second edition, 1984.
72 ## Author: Arno Onken <asnelt@asnelt.org>
73 ## Description: Moments of the Weibull distribution
75 function [m, v] = wblstat (scale, shape)
82 if (! isempty (scale) && ! ismatrix (scale))
83 error ("wblstat: scale must be a numeric matrix");
85 if (! isempty (shape) && ! ismatrix (shape))
86 error ("wblstat: shape must be a numeric matrix");
89 if (! isscalar (scale) || ! isscalar (shape))
90 [retval, scale, shape] = common_size (scale, shape);
92 error ("wblstat: scale and shape must be of common size or scalar");
97 m = scale .* gamma (1 + 1 ./ shape);
98 v = (scale .^ 2) .* gamma (1 + 2 ./ shape) - m .^ 2;
100 # Continue argument check
101 k = find (! (scale > 0) | ! (scale < Inf) | ! (shape > 0) | ! (shape < Inf));
112 %! [m, v] = wblstat (scale, shape);
113 %! expected_m = [3.0000, 3.5449, 4.4649, 5.4384, 6.4272, 7.4218];
114 %! expected_v = [9.0000, 3.4336, 2.6333, 2.3278, 2.1673, 2.0682];
115 %! assert (m, expected_m, 0.001);
116 %! assert (v, expected_v, 0.001);
120 %! [m, v] = wblstat (6, shape);
121 %! expected_m = [ 6.0000, 5.3174, 5.3579, 5.4384, 5.5090, 5.5663];
122 %! expected_v = [36.0000, 7.7257, 3.7920, 2.3278, 1.5923, 1.1634];
123 %! assert (m, expected_m, 0.001);
124 %! assert (v, expected_v, 0.001);