 function [delfx,cost] = subgrad(m,x,blk,blkp)
%function [delfx,cost] = subgrad(m,x,blk,blkp)
%  calculates an element of the subgradient set
%  for the function f(X) := sigma_max { e^X M e^{-X} }
%  at an arbitrary given point X. this routine
%  assumes that the last coordinate of the X
%  vector is fixed at 0, so there are NBLK-1 variables
%  in the X vector
 [nblk,dum] = size(blk);
 delfx = zeros(length(x),1);
 sm = m;
 for i=1:nblk-1
   sm(blkp(i,2):blkp(i+1,2)-1,:) = exp(x(i))*sm(blkp(i,2):blkp(i+1,2)-1,:);
   sm(:,blkp(i,1):blkp(i+1,1)-1) = exp(-x(i))*sm(:,blkp(i,1):blkp(i+1,1)-1);
 end
 [u,s,v] = svd(sm);
 cost = s(1,1);

 for i=1:nblk-1
   w1 = abs( u(blkp(i,2):blkp(i+1,2)-1,1)'* u(blkp(i,2):blkp(i+1,2)-1,1) );
   w2 = abs( v(blkp(i,1):blkp(i+1,1)-1,1)'* v(blkp(i,1):blkp(i+1,1)-1,1) );
   delfx(i) = s(1,1) * (w1-w2);
 end
%
% Copyright MUSYN INC 1991,  All Rights Reserved
