Algorithms for Solving Nonhomogeneous Generalized Sylvester Matrix Equations