function vol=volume(q)
  % Volume of a d-simplex given by its (d+1) vertices q.
  % q : n-by-(d+1) array, q(:,i) is the i-th vertex of the d-simplex
  n=size(q,1);d=size(q,2)-1;
  AK=q(:,2:end)-q(:,1);
  if d==n
    vol=abs(det(AK))/factorial(d);
  else
    vol=sqrt(abs(det(AK'*AK)))/factorial(d);
  end
end
