function [pivot,nzpos] = findfirstnonzero(v)
% MATLAB function that returns the first non-zero component of the argument
% vector and its position.
% \textbf{WARNING: in the presence of roundoff this function might return spurious
% results!}
nzi = find(v ~= 0); % get vector of indices of non-zero components
if (isempty(nzi)), nzpos =0; pivot = 0; 
else 
    nzpos = nzi(1); pivot = v(nzpos); 
end
