%function [lb,bw,az,actit,ec] =  mup(mat,nblk,blk,blkp,repp,fulp,sv,opt)
%
%	Power iteration for mu lower bound.  Not to be called by user.

 function [lb,bw,az,actit,ec] =  mup(mat,nblk,blk,blkp,repp,fulp,sv,opt)

  maxit = 30;
  if any(opt=='t')
    maxit = 300;
  end
  tols = [1e-4 1e-4 1e-4];   beta = [-15 -16];  
  actit = 0;  count = [0 0];
  cf = 0;  % cf tags convergence  0 not converged
           %                      1 converged
  bw = sv;
% az = bw;
 [innr innc] = size(mat);

  while actit < maxit & cf == 0
    actit = actit + 1;
    oldbeta = beta;     oldbw = bw;    oldaz = az;
    [bw,az,beta,ec] = pwr_1(mat,nblk,blk,blkp,repp,fulp,bw);
    if ec ~= 0,  
	if isempty(az)
          az = crand(innr,2);
	end
	return;   
    end
    dbeta = max(abs(oldbeta - beta));
%
    if dbeta < tols(1)
      delbeta = abs(beta(1) - beta(2));
      if delbeta < tols(2)
          count(1) = count(1) + 1;
        else
          count = [0 0];
      end % if delbeta
    else
      count = [0 0];
    end % if dbeta
%
    if count(1) >= 2
      dbw = oldbw - bw;
      daz = oldaz - az;
      nbw(1) = norm(dbw(:,1));      nbw(2) = norm(dbw(:,2));
      naz(1) = norm(daz(:,1));      naz(2) = norm(daz(:,2));
      if max([ nbw naz ]) < tols(3)
          count(2) = count(2) + 1;
        else
          count(2) = 0;
      end %if max
      if count(2) >= 2
        cf = 1;
        lb = 0.5*(beta(1) + beta(2));
      end % if count(2)
    end % if count(1)
  end % while actit

  if cf == 0
    ec = -1;    
    actit = maxit;
  end %if cf
%
% Copyright MUSYN INC 1991,  All Rights Reserved
