function P = metropolis(v,Q)
%
% P = metropolis(v)
% P = metropolis(v,Q)
%
n = length(v);
if (nargin == 1)
  Q = randstocsym(n);
end
V = repmat(v,n,1);
W = repmat(v',1,n);
% W = V';
P = zeros(n);
P(V>=W) = Q(V>=W);
P(V<W) = Q(V<W) .* V(V<W) ./ W(V<W);
P = P - diag(diag(P));
d = 1 - sum(P,2);
P = P + diag(d);