% makes the first column of a slice in dimension d of tensor t as small
% as possible by a right Householder rotation of t; also returns the
% Householder vector h, the norm nmin of the first column, and the slice
% number smin

function [t,h,nmin,smin] = tmincol(t,d)

dim = tdimensions(t);

nmin=Inf;
for s=1:dim(d),
  a = tgetmatrix(t,s,d);
  [u sigma v] = svd(a,0);
  c = size(a,2);
  n = sigma(c,c);
  if n < nmin,
    nmin = n;
    smin = s;
    vmin = v(:,c);
  end
end

h = -house(vmin);
t = trighthouse(t,d,h);
