function M = extend_ls_mat(A, n)
    if n == 0
        M = A;
        return;
    elseif n > 1
        A = extend_ls_mat(A, n - 1);
    end
    M = [];
    for i=1:size(A,2)
        for j=i:size(A,2)
            M = [M A(:,i).*A(:,j)];
        end
    end
end