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: ncp.m
    path of file: ./repos/lrslibrary/algorithms/ntf/bcuNCP
    
    the code of the file until where you have to start completion: function [A,Out] = ncp(M,r,opts)
% ncp: nonnegative tensor decomposition (CANDECOMP/PARAFAC) by block-coordinate update
%  min 0.5*||M - A_1\circ...\circ A_N||_F^2  
%  subject to A_1>=0, ..., A_N>=0
%
% input: 
%       M: input nonnegative tensor
%       r: estimated rank (each A_i has r columns); require exact or moderate overestimates
%       opts.
%           tol: tolerance for relative change of function value, default: 1e-4
%           maxit: max number of iterations, default: 500
%           maxT: max running time, default: 1e3
%           rw: control the extrapolation weight, default: 1
%           A0: initial point in cell struct, default: Gaussian random
%           matrices
% output:
%       A: nonnegative ktensor
%       Out.
%           iter: number of iterations
%           hist_obj: history of objective values
%           hist_rel: history of relative objective changes (row 1) and relative residuals (row 2)
%
% require MATLAB Tensor Toolbox from
% http://www.sandia.gov/~tgkolda/TensorToolbox/
%

    
function [A,Out] = ncp(M,r,opts)
% ncp: nonnegative tensor decomposition (CANDECOMP/PARAFAC) by block-coordinate update
%  min 0.5*||M - A_1\circ...\circ A_N||_F^2  
%  subject to A_1>=0, ..., A_N>=0
%
% input: 
%       M: input nonnegative tensor
%       r: estimated rank (each A_i has r columns); require exact or moderate overestimates
%       opts.
%           tol: tolerance for relative change of function value, default: 1e-4
%           maxit: max number of iterations, default: 500
%           maxT: max running time, default: 1e3
%           rw: control the extrapolation weight, default: 1
%           A0: initial point in cell struct, default: Gaussian random
%           matrices
% output:
%       A: nonnegative ktensor
%       Out.
%           iter: number of iterations
%           hist_obj: history of objective values
%           hist_rel: history of relative objective changes (row 1) and relative residuals (row 2)
%
% require MATLAB Tensor Toolbox from
% http://www.sandia.gov/~tgkolda/TensorToolbox/
%
% More information can be found at:
% http://www.caam.rice.edu/~optimization/bcu/

%% Parameters and defaults
if isfield(opts,'tol');   tol = opts.tol;     else tol = 1e-4;   end