Numerical solution to generalized Lyapunov/Stein and rational Riccati equations in stochastic control