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: Least_rMTFL.m
    path of file: ./repos/MALSAR/MALSAR/functions/rMTFL
    
    the code of the file until where you have to start completion: %% FUNCTION Least_rMTFL
%   Robust Multi-Task Learning with Least Squares Loss.
%
%% OBJECTIVE
%   argmin_W ||X(P+Q) - Y||_F^2 + lambda1*||P||_{1,2} + lambda2*||Q^T||_{1,2}
%   s.t. W = P + Q
%
%% INPUT
%   X: {n * d} * t - input matrix
%   Y: {n * 1} * t - output matrix
%   lambda1: regularized parameter
%   lambda2: regularized parameter
%
%   (Optional)
%   opts.lFlag: estimate the upper bound of Lipschitz constant if nonzero, zero otherwise 
%
%% OUTPUT
%   W: model: d * t
%   P: output weight
%   Q: output weight
%   fun: function values
%
%% LICE
    
function value
funcVal = cat(1, funcVal, norm(X*(P(:) + Q(:)) - y)^2 + lambda1*L12norm(P) + lambda2*L12norm(Q'));

%count = 0;
for iter = 1:opts.maxIter
    P_old = P; Q_old = Q;
    t_old = t_new;
    gradvec = 2*(XtX*(Pn(:)+Qn(:)) - Xty);
    gradmat = reshape(gradvec,d,m);
    % If we estimate the upper bound of Lipschitz constant, no line search
    % is needed.
    if lFlag
        P = proximalL12norm(Pn - gradmat/L, lambda1/L);
        Q = proximalL12norm(Qn' - gradmat'/L, lambda2/L)';
    else
        % line search 
        for inneriter = 1:20
            P = proximalL12norm(Pn - gradmat/L, lambda1/L);
            Q = proximalL12norm(Qn' - gradmat'/L, lambda2/L)';
            dP = P - Pn;  dQ = Q - Qn; 
            if 2*((dP(:) + dQ(:))'*XtX*(dP(:) + dQ(:))) <= L*sum(sum((dP.*dP + dQ.*dQ)))
                break;
            else
                L = L*2;
            end