first implementation of algorithm in MATLAB code