You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: solve_proj2.m
    path of file: ./repos/ostd/STOC-RPCA
    
    the code of the file until where you have to start completion: % solve the problem:
%   min_{x,e} 0.5*|z-Dx-e|_2^2 + 0.5*lambda1*|x|_2^2 + lambda2*|e|_1
%
% solve the projection by APG
% input:
%   z - data point
%   D - basis matrix
%   lambda1, lambda2 - tradeoff parameters
% output:
%   
    
function [x,e] = solve_proj2(z,D,lambda1,lambda2)
  % initialization
  [ndim,ncol] = size(D);
  e = zeros(ndim,1);
  x = zeros(ncol,1);
  I = eye(ncol);
  converged = false;
  maxIter = inf;
  iter = 0;
  % alternatively update
  DDt = inv(D'*D+lambda1*I)*D';
  while ~converged
    iter = iter + 1;
    xtemp = x;
    x = DDt*(z-e);
    % x = (D'*D + lambda1*I)\(D'*(z-e));
    etemp = e;
    e = thres(z-D*x,lambda2);
    stopc = max(norm(e-etemp), norm(x-xtemp))/ndim;
    if stopc < 1e-6 || iter > maxIter
      converged = true;
    end