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: cpd3_sgsd.m
    path of file: ./repos/mtt/libs/tensorlab
    
    the code of the file until where you have to start completion: function [U,output] = cpd3_sgsd(T,U0,options)
%CPD3_SGSD CPD by simultaneous generalized Schur decomposition.
%   [U,output] = cpd3_sgsd(T,U0) computes the factor matrices U{1}, U{2}
%   and U{3} belonging to a canonical polyadic decomposition of the third-
%   order tensor T. The algorithm is initialized with the factor matrices
%   U0{n}. The number of rank-one terms R should satisfy sum(R <= size(T))
%   >= 2. The structure output returns additional information:
%
%      output.fval       - The value of the objective function, which
%                          is the Frobenius norm of the lower triangular
%                          entries of the 'upper triangular' matrices
%                          Rk(:,:,k) == Q*T(:,:,k)*Z, in every iteration.
%      output.info       - The circumstances under which the procedure
%                          terminated:

    
function [U,output] = cpd3_sgsd(T,U0,options)
%CPD3_SGSD CPD by simultaneous generalized Schur decomposition.
%   [U,output] = cpd3_sgsd(T,U0) computes the factor matrices U{1}, U{2}
%   and U{3} belonging to a canonical polyadic decomposition of the third-
%   order tensor T. The algorithm is initialized with the factor matrices
%   U0{n}. The number of rank-one terms R should satisfy sum(R <= size(T))
%   >= 2. The structure output returns additional information:
%
%      output.fval       - The value of the objective function, which
%                          is the Frobenius norm of the lower triangular
%                          entries of the 'upper triangular' matrices
%                          Rk(:,:,k) == Q*T(:,:,k)*Z, in every iteration.
%      output.info       - The circumstances under which the procedure
%                          terminated:
%                             1: Objective function tolerance reached.
%                             2: Maximum number of iterations reached.
%      output.iterations - The number of iterations.
%
%   cpd3_sgsd(T,U0,options) may be used to set the following options:
%
%      options.MaxIter = 200 - The maximum number of iterations.
%      options.TolFun = 1e-4 - The tolerance for the objective function
%                              between two successive iterates.

%   Authors: Mikael Sorensen (Mikael.Sorensen@kuleuven-kulak.be),
%            Laurent Sorber (Laurent.Sorber@cs.kuleuven.be)
%            Lieven De Lathauwer (Lieven.DeLathauwer@kuleuven-kulak.be)
%
%   References:
%   [1] L. De Lathauwer, B. De Moor, J. Vandewalle, "Computation of the
%       Canonical Decomposition by Means of a Simultaneous Generalized 
%       Schur Decomposition," SIAM J. Matrix Anal. Appl., Vol. 26, 2004,
%       pp. 295-327.
%   [2] A.-J. van der Veen, A. Paulraj, "An Analytical Constant Modulus 
%       Algorithm," IEEE Trans. Signal Proc., Vol. 44, 1996, pp. 1136-1155.

% Incomplete/sparse tensors not supported yet.
T = fmt(T,true);
if isstruct(T)
    error('This method does not yet support incomplete/sparse tensors.');
end