We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defpowerMatrix(A,k):'''kth power of a 2 x 2 square matrix'''if(k==0):I2=[[1,0],[0,1]]# 2 x 2 identity matrixreturnI2elif(k==1):# basereturnAelif(k>1):# recursiveA_less_1=powerMatrix(A,k-1)A_last=AB=[[0,0],[0,0]]foriinrange(len(A_less_1)):forjinrange(len(A_less_1[0])):forlinrange(len(A_last)):B[i][j]+=A_less_1[i][l]*A_last[l][j]returnBif__name__=="__main__":A=[[-2,-9],[1,4]]A500=powerMatrix(A,500)A1000=powerMatrix(A500,2)[print(*i,sep='\n')foriinA1000]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Linear Algebra Foundations #7 - The 1000th Power of a Matrix
You are viewing a single comment's thread. Return to all comments →