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);
P = zeros(n);
index = find(V >= W);
P(index) = Q(index);
index = find(V < W);
P(index) = Q(index) .* (V(index) ./ W(index));
P = P - diag(diag(P));
d = 1 - sum(P,2);
P = P + diag(d);