function N = noll(Z,tol)
% N = noll(Z,tol)
% compute the null space of a nearly signular matrix
%  
%  INPUT DATA       DESCRIPTION
%  ----------       --------------------------------------------
%     Z             the matrix for which you seek the null space
%     tol           tolerance of the smallest singular value of Z, deflaut 0.01 
%
%  OUTPUT DATA      DESCRIPTION
%  -----------      --------------------------------------------
%     N             the null space 

if nargin == 1, tol = 0.01; end       % default value of tolerance

[U,S,V] = svd(Z);   % the singular value decomposition Z = U*S*V'

idx = find( diag(S) < tol );    % col's of V in the null space of Z

N = V(:,idx);

% ----------------------------------------------------------------- noll.m


