function [ A ] = Optimize_Anew( W,X,lambda,Ai,alpha  )
%OPTIMIZE_A3 此处显示有关此函数的摘要
%   此处显示详细说明
tmp1=X'*W;
XWWX=tmp1*tmp1';
d=diag(XWWX);

H=bsxfun(@plus,-2.*XWWX,d);
H=bsxfun(@plus,H,d');

[n,~,m]=size(Ai);
AA=zeros(n,n);
for i=1:m
    AA=AA+alpha(i).*Ai(:,:,i);
end
AA=AA.*lambda;
A=zeros(n,n);
for i=1:n
     idx=find(AA(i,:));
%     idx_0=setdiff(1:n,[idx,i]);
     [min_h,min_hidx]=min(H(i,setdiff(1:n,i)));
     if min_hidx>=i
         min_hidx=min_hidx+1;
     end
     if(ismember(min_hidx,idx))
         try
            gamma=fzero(@(x)rootfinding(x,AA(i,idx),H(i,idx)),[-min_h+eps,10000]);
         catch
             gamma=fzero(@(x)rootfinding(x,AA(i,idx),H(i,idx)),[-min_h+0.01*eps,10000]);
         end
         A(i,idx)=AA(i,idx)./(H(i,idx)+gamma);
     else
         gamma=-min_h;
         tmp=rootfinding(-min_h,AA(i,idx),H(i,idx));
         if tmp<=0
            A(i,idx)=AA(i,idx)./(H(i,idx)+gamma);
            A(i,min_hidx)=1-sum(A(i,idx));
         else
            try
                gamma=fzero(@(x)rootfinding(x,AA(i,idx),H(i,idx)),[-min_h+eps,10000]);
            catch
                gamma=fzero(@(x)rootfinding(x,AA(i,idx),H(i,idx)),[-min_h+0.01*eps,10000]);
            end
            A(i,idx)=AA(i,idx)./(H(i,idx)+gamma); 
         end
     end
%     [min_h,~]=min(H(i,setdiff(1:n,i)));
%     try
%     gamma=fzero(@(x)rootfinding(x,AA(i,:),H(i,:)),[-min_h+eps,10000]);
%     catch
%         i
%     end
%     A(i,:)=AA(i,:)./(H(i,:)+gamma);
end

end

