0001 function x = qbeta(p,a,b)
0002
0003
0004
0005
0006
0007
0008
0009 if any(any((a<=0)|(b<=0)))
0010 error('Parameter a or b is nonpositive')
0011 end
0012 if any(any(abs(2*p-1)>1))
0013 error('A probability should be 0<=p<=1, please!')
0014 end
0015 b = min(b,100000);
0016
0017 x = a ./ (a+b);
0018 dx = 1;
0019 while any(any(abs(dx)>256*eps*max(x,1)))
0020 dx = (betainc(x,a,b) - p) ./ dbeta(x,a,b);
0021 x = x - dx;
0022 x = x + (dx - x) / 2 .* (x<0);
0023 x = x + (1 + (dx - x)) / 2 .* (x>1);
0024 end
0025
0026