In this paper, we consider a reconfigurable intelligent surface (RIS) and model it by using multiport network theory. We first compare the representation of RIS by using $Z$-parameters and $S$-parameters, by proving their equivalence and discussing their distinct features. Then, we develop an algorithm for optimizing the RIS configuration in the presence of electromagnetic mutual coupling. We show that the proposed algorithm based on optimizing the $S$-parameters results in better performance than existing algorithms based on optimizing the $Z$-parameters. This is attributed to the fact that small perturbations of the step size of the proposed algorithm result in larger variations of the $S$-parameters, hence increasing the convergence speed of the algorithm.