Power method calculation code