function [D,Jnow]=Metaface_single_iteration(X,D,lambda,iteration)
% output:D an dictionary we want to learn with size of m by p
% input :
%       X  --   denote the dataset matrix with size of m by n,
%               each column is a sample
%       D  --   the initialized Dictionary
%       lamba  --- denote a coeff of l1_ls
% the formula is that : J= argmin(D,alpha){norm(X-D*alpha,2)^2+lamta*norm(alpha,1)}

% Fix D, solove alpha, using l1_ls function, begin

for i = 1:size(X,2)
    fprintf(['Now iteration=' num2str(iteration) ' the processing ratio=' num2str(100*i/size(X,2)) '\n']);
    [s,status] = l1_ls(D, X(:,i), lambda,1e-3,true);
    if sum(status=='Solved')~=6
    fprintf('l1 optimation can not get the result!!!');
    end
    alpha(:,i)=single(s);
end
%optimation one column by one begin

% Fix D,solove alpha, using l1_ls function,end

% Fix alpha, update D. begin
for i=1:size(D,2)
   ai=alpha(i,:);
   Y=X-D*alpha+D(:,i)*ai;
   di=Y*ai';
   di=di./norm(di,2);
   D(:,i)=di;
   clear Y;
end
% Fix alpha, update D. end
zz=X-D*alpha;zalpha=alpha(:);
Jnow=zz(:)'*zz(:)+lambda*sum(abs(zalpha(:)))
