This code corresponds to the converted code from matlab to c++ for the online version