function scale = sestck(x,start,c,k,tol)
% Computes Tukey's biweight objectief function (scale) corresponding
% with the mahalanobis distances x.
if start>0
s = start;
else y=abs(x);
[n,p]=size(x);
if ((n==1) & (p>1))
x = x'; [n,p] = size(x);
end
x = sort(x);
if floor(n/2) == n/2
s = (x(n/2,:) + x((n+2)/2,:))/2;
else
s = x((n+1)/2,:);
end
s = s/0.6745;
end
crit = 2*tol;
rhoold = mean(rhobiweight(x/s,c))-k;
while crit >= tol
delta = rhoold/mean(psibiweight(x/s,c).*(x/(s^2)));
isqu = 1; okay = 0;
while ((isqu<10) & (okay~=1))
rhonew = mean(rhobiweight(x/(s+delta),c))-k;
if abs(rhonew) < abs(rhoold)
s = s+delta;
okay = 1;
else
delta = delta/2;
isqu = isqu+1;
end
end
if isqu == 10
crit = 0;
else
crit = (abs(rhoold)-abs(rhonew))/(max([abs(rhonew),tol]));
end
rhoold = rhonew;
end
scale = abs(s);