there is a tricky bug in ufun_Atta_L. for some values the .cols() member function used in the final part of the program is given an index out of bounds. think the approach with k = find( where do you work ) is not well done, because the indexing over cols is tricky. switched to the other version ufun_Atta_L2.