function G=gradBaCo(q)
  % Gradients of barycentric coordinates on 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
  %   G : (d+1)-by-n array, G(i,:) is the gradient of the (i-1)-th barycentric coordinates
  n=size(q,1);d=size(q,2)-1;
  AK=q(:,2:end)-q(:,1);
  G=zeros(n,d+1);
  if d==n
    G(:,2:d+1)=inv(AK)';
  else
    G(:,2:d+1)=AK*inv(AK'*AK);
  end
  G(:,1)=-sum(G(:,2:d+1),2);
  G=G'; % to be compatible with gradBaCo property of fc_simesh.siMeshElt object
end
