function x = medianrang(i,n)

a = i;
b = n-a+1;
pvek = [0 1];
while abs(diff(pvek)) > 1e-12
  p = mean(pvek);
  if betainc(p,a,b) > 0.5
    pvek(2) = p;
  else
    pvek(1) = p;
  end
end
  
x = mean(pvek);
