home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SPECFUN.DI$ / BETAINC.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  927 b   |  31 lines

  1. function y = betainc(x,a,b)
  2. %BETAINC Incomplete beta function.
  3. %    y = betainc(x,a,b).
  4. %    The elements of x must be in the interval [0,1].
  5. %    a and b must be scalars.
  6. %
  7. %    See also BETA.
  8.  
  9. %    Ref: Abramowitz & Stegun, Handbook of Mathemtical Functions, sec. 26.5.
  10. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  11.  
  12. if any(any(x < 0 | x > 1))
  13.         error('In betainc(X,a,b), X must be in the interval [0,1].')
  14. end
  15. if max(size(a)) > 1 | max(size(b)) > 1
  16.         error('In betainc(X,a,b), a and b must be scalars.');
  17. end
  18. if nargin < 3
  19.         error('In betainc(X,a,b), all three input arguments must be given.');
  20. end
  21.  
  22. [m,n] = size(x);
  23. y = zeros(m,n);
  24. bt = y;
  25. k = find(x > 0 & x < 1);
  26. bt(k) = exp(gammaln(a+b)-gammaln(a)-gammaln(b) + a*log(x(k)) + b*log(1-x(k)));
  27. k = find(x < (a+1)/(a+b+2));
  28. y(k) = bt(k) .* betacore(x(k),a,b) / a;
  29. k = find(x >= (a+1)/(a+b+2));
  30. y(k) = 1 - bt(k) .* betacore(1-x(k),b,a) / b;
  31.