home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / statistics / distributions / weibull_cdf.m < prev    next >
Encoding:
Text File  |  1997-02-19  |  1.9 KB  |  66 lines

  1. ## Copyright (C) 1995, 1996, 1997  Kurt Hornik
  2. ## 
  3. ## This program is free software; you can redistribute it and/or modify
  4. ## it under the terms of the GNU General Public License as published by
  5. ## the Free Software Foundation; either version 2, or (at your option)
  6. ## any later version.
  7. ## 
  8. ## This program is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. ## General Public License for more details. 
  12. ## 
  13. ## You should have received a copy of the GNU General Public License
  14. ## along with this file.  If not, write to the Free Software Foundation,
  15. ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. ## usage:  weibull_cdf (x, alpha, sigma)
  18. ##
  19. ## Compute the cumulative distribution function (CDF) at x of the
  20. ## Weibull distribution with shape parameter alpha and scale parameter
  21. ## sigma, which is 1 - exp(-(x/sigma)^alpha), x >= 0.
  22.   
  23. ## Author:  KH <Kurt.Hornik@ci.tuwien.ac.at>
  24. ## Description:  CDF of the Weibull distribution
  25.  
  26. function cdf = weibull_cdf (x, shape, scale)
  27.   
  28.   if (nargin != 3)
  29.     usage ("weibull_cdf (x, alpha, sigma)");
  30.   endif
  31.  
  32.   [retval, x, shape, scale] = common_size (x, shape, scale);
  33.   if (retval > 0)
  34.     error (["weibull_cdf:  ", ...
  35.         "x, alpha and sigma must be of common size or scalar"]);
  36.   endif
  37.  
  38.   [r, c] = size (x);
  39.   s = r * c;
  40.   x = reshape (x, 1, s);
  41.   shape = reshape (shape, 1, s);
  42.   scale = reshape (scale, 1, s);
  43.  
  44.   cdf = NaN * ones (1, s);
  45.   
  46.   ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf));
  47.   
  48.   k = find ((x <= 0) & ok);
  49.   if any (k)
  50.     cdf(k) = zeros (1, length (k));
  51.   endif
  52.   
  53.   k = find ((x > 0) & (x < Inf) & ok);
  54.   if any (k)
  55.     cdf(k) = 1 - exp (- (x(k) ./ scale(k)) .^ shape(k));
  56.   endif
  57.   
  58.   k = find ((x == Inf) & ok);
  59.   if any (k)
  60.     cdf(k) = ones (1, length (k));
  61.   endif
  62.   
  63.   cdf = reshape (cdf, r, c);
  64.   
  65. endfunction
  66.