MATLAB classic algorithm program