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: tv3d.m
    path of file: ./repos/3DCS/algorithms
    
    the code of the file until where you have to start completion: function X = tv3d(H,P,Z,lambda,opts)
%TV3D  Three dimensional total variation (3DTV) regularization for three
%dimensional (3D) compressive sensing reconstruction problem.
%   [model]
%   ---------------------------------------
%   min \sum_i |H*X_i|_1 + lambda*|X*OP|_1
%   s.t. P_i*X_i=Z_i, i = 1,...,F
%   ------------------------------------------
%   [variables]
%     N    -- Nyquist number
%     F    -- frame number
%     M    -- measurement number
%     P    -- measurement matrix array: [M, N, F]
%     Z    -- meassurement array: [M, F]
%     X_0  -- initial X: [N, F]
%     X_gt -- groundtrue X: [N, F]
%     H    -- gradient operator
%   See also GENTV3DOP, TV, CS3D.

mu0     = opts.mu0;
mumax   = opts.mumax;
maxiter = opts.maxiter;
rho     = opts.rho;
tol     = opts.tol;

[~,N,F]  = size(P);

%%% OP -- intra-frame operator
OP = -triu(ones(F,F-1),0)+triu(ones(F,F-1),-1)...
            -triu(ones(F,F-1),0)+triu(ones(F,F-1),1);

%%% lambda
% lambda=norm(H*double(X_0),1)/norm(double(X_0)*OP,1); 

%%% initialization
% X=X_0;
X = zeros(N, F);
mu = mu0;
W = H*X;
V = X*OP;
R = zeros(size(W));
S = zeros(size(V));
T = zeros(size(Z));

    
function X = tv3d(H,P,Z,lambda,opts)
%TV3D  Three dimensional total variation (3DTV) regularization for three
%dimensional (3D) compressive sensing reconstruction problem.
%   [model]
%   ---------------------------------------
%   min \sum_i |H*X_i|_1 + lambda*|X*OP|_1
%   s.t. P_i*X_i=Z_i, i = 1,...,F
%   ------------------------------------------
%   [variables]
%     N    -- Nyquist number
%     F    -- frame number
%     M    -- measurement number
%     P    -- measurement matrix array: [M, N, F]
%     Z    -- meassurement array: [M, F]
%     X_0  -- initial X: [N, F]
%     X_gt -- groundtrue X: [N, F]
%     H    -- gradient operator
%   See also GENTV3DOP, TV, CS3D.

mu0     = opts.mu0;
mumax   = opts.mumax;
maxiter = opts.maxiter;
rho     = opts.rho;
tol     = opts.tol;

[~,N,F]  = size(P);

%%% OP -- intra-frame operator
OP = -triu(ones(F,F-1),0)+triu(ones(F,F-1),-1)...
            -triu(ones(F,F-1),0)+triu(ones(F,F-1),1);

%%% lambda
% lambda=norm(H*double(X_0),1)/norm(double(X_0)*OP,1); 

%%% initialization
% X=X_0;
X = zeros(N, F);
mu = mu0;
W = H*X;
V = X*OP;
R = zeros(size(W));
S = zeros(size(V));
T = zeros(size(Z));
    
%%% 
% disp('precalculation of TV3D')
HT  = H';
HTH = H'*H;
I   = eye(N);
X_update_pinv = zeros(N,N,F);
for i = 1:F
    PTP = P(:,:,i)'*P(:,:,i);
    if i==1 || i==F
        X_update_pinv(:,:,i) = (HTH+I+PTP)\I;
    else
        X_update_pinv(:,:,i) = (HTH+2*I+PTP)\I;
    end