Added the algorithm for matrix rotation