root measurement algorithm in MATLAB