A numerical method to compute the running coupling in asymptotically free theories