clear all


numsim=1;
krange=[3 5 8 10 12 15 20 23 26 30 40 50 100 200];
% krange=[200];
s = 1.5;
epsilon=0.00001;

total=[];
for k=krange,
  p = abs(randn(k,1)); p = p /sum(p);
% $$$   if k==3
% $$$     p(1,1) = 0.95 * s/2;
% $$$     p(2,1) = 0.95 -p(1,1);
% $$$     p(3:k,1) = (0.05)/(k-2);
% $$$   else
% $$$     p(1,1) = 0.95 * s/3;
% $$$     p(2:3,1) = (0.95 -p(1,1))/2;
% $$$     p(4:k,1) = (0.05)/(k-3);
% $$$   end

  for iter=1:numsim
    r=zeros(k,k);
    for i =1:k
      r(i,i+1:k) = min(max(epsilon,p(i) ./ (p(i)+p(i+1:k,1)')+0.1*randn(1,k-i)),1-epsilon) ;
      r(i+1:k,i) = 1 - r(i,i+1:k)';
    end
    [p2, B] = method2(r);
    [p2iter, B] = method2iter(r);
  end
end
% [p2 p2iter]