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.
# Enter your code here. Read input from STDIN. Print output to STDOUTdefdeterminant(A:list[list[int]])->int:returnA[0][0]*A[1][1]-A[1][0]*A[0][1]defmatrixSubtract(B,A):C=[[0,0],[0,0]]foriinrange(len(B)):forjinrange(len(B[0])):C[i][j]=B[i][j]-A[i][j]returnCdefscalarMultiply(A,k:int):Ak=[[0,0],[0,0]]foriinrange(len(A)):forjinrange(len(A[0])):Ak[i][j]=k*A[i][j]returnAkif__name__=="__main__":A=[[0,1],[-2,-3]]I2=[[1,0],[0,1]]# 2 x 2 identity matrixeigval=-10lst_eigvals=[]while(eigval<5):val=determinant(matrixSubtract(scalarMultiply(I2,eigval),A))if(val==0):# |λI - A| = 0lst_eigvals+=[eigval]eigval+=1print(*lst_eigvals,sep='\n')
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 #9 - Eigenvalues
You are viewing a single comment's thread. Return to all comments →