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_inv.m < prev    next >
Encoding:
Text File  |  1997-02-19  |  1.9 KB  |  64 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_inv (x, lambda, alpha)
  18. ##
  19. ## Compute the quantile (the inverse of the CDF) at x of the Weibull
  20. ## distribution with shape parameter alpha and scale parameter sigma.
  21.   
  22. ## Author:  KH <Kurt.Hornik@ci.tuwien.ac.at>
  23. ## Description:  Quantile function of the Weibull distribution
  24.  
  25. function inv = weibull_inv (x, shape, scale)
  26.   
  27.   if (nargin != 3)
  28.     usage ("weibull_inv (x, alpha, sigma)");
  29.   endif
  30.  
  31.   [retval, x, shape, scale] = common_size (x, shape, scale);
  32.   if (retval > 0)
  33.     error (["weibull_inv:  ", ...
  34.         "x, alpha and sigma must be of common size or scalar"]);
  35.   endif
  36.  
  37.   [r, c] = size (x);
  38.   s = r * c;
  39.   x = reshape (x, 1, s);
  40.   shape = reshape (shape, 1, s);
  41.   scale = reshape (scale, 1, s);
  42.  
  43.   inv = NaN * ones (1, s);
  44.   ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf));
  45.   
  46.   k = find ((x == 0) & ok);
  47.   if any (k)
  48.     inv(k) = -Inf * ones (1, length (k));
  49.   endif
  50.   
  51.   k = find ((x > 0) & (x < 1) & ok);
  52.   if any (k)
  53.     inv(k) = scale(k) .* (- log (1 - x(k))) .^ (1 ./ shape(k));
  54.   endif
  55.  
  56.   k = find ((x == 1) & ok);
  57.   if any (k)
  58.     inv(k) = Inf * ones (1, length (k));
  59.   endif
  60.   
  61.   inv = reshape (inv, r, c);
  62.   
  63. endfunction
  64.