function [mufull,mudiag,fullcount,diagcount] = calcmu(M,iter)

%
%	This short program is designed to provide a numerical extimation
%	of the structured singular value.
%
%		Author:	Greg Stewart
%		Date:		October 24, 2001.
%

%
%	Determine the size of M.
%
n = length(M);
maxmu = 99999;


%
%	Search for a FULL complex matrix Delta that will result in an 
%	unstable M-Delta pair.
%
fullcount = 0;
mufull = maxmu;
for k = 1:iter
   Delta_temp = rand(n,n) + sqrt(-1)*rand(n,n);
   normdelta = max(svd(Delta_temp));
   %Delta_temp = Delta_temp/normdelta;	% ensuring that max(svd(Delta))=1
   if max(abs(eig(M*Delta_temp))) >= 1
      fullcount = fullcount + 1;
      if normdelta < mufull
         Deltafull = Delta_temp;
         mufull = normdelta;
      end
   end
end

%
%	Search for DIAGONAL complex matrix Delta that will result in an 
%	unstable M-Delta pair.
%
diagcount = 0;
mudiag = maxmu;
for k = 1:iter
	Delta_temp = diag(rand(1,n)) + sqrt(-1)*diag(rand(1,n));
   normdelta = max(svd(Delta_temp));
   %Delta_temp = Delta_temp/normdelta;	% ensuring that max(svd(Delta))=1
   if max(abs(eig(M*Delta_temp))) >= 1
      diagcount = diagcount + 1;
      if normdelta < mudiag
         Deltadiag = Delta_temp;
         mudiag = normdelta;
      end
   end
end