%
% bases of null space and its complement space
%     mat : matrix
%     null : bases of null space, max x = 0 (column vectors)
%     comlement : bases of orthogonal complement space (column vectors)
%
function [null, complement] = null_and_complement_null (mat)
    [U,S,V] = svd(mat,0);
    m = size(S,1); % number of independent equations
    n = size(S,2); % dimension

    null = [];       % null space
    complement = []; % complement null space
    for k=1:m
        if S(k,k) < -eps || eps < S(k,k)
            complement = [complement, V(:,k)];
        else
            null = [null, V(:,k)];
        end
    end
    if (m < n)
        null = [null, V(:,m+1:n)];
    end
end
