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:a,b,c=A[0]det1=a*(A[1][1]*A[2][2]-A[2][1]*A[1][2])det2=-b*(A[1][0]*A[2][2]-A[2][0]*A[1][2])det3=c*(A[1][0]*A[2][1]-A[2][0]*A[1][1])returndet1+det2+det3defmatrixSubtract(B,A):C=[[0,0,0],[0,0,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,0,0],[0,0,0]]foriinrange(len(A)):forjinrange(len(A[0])):Ak[i][j]=k*A[i][j]returnAkif__name__=="__main__":A=[[1,-3,3],[3,-5,3],[6,-6,4]]I3=[[1,0,0],[0,1,0],[0,0,1]]# 3 x 3 identity matrixeigval=-10lst_eigvals=[]while(eigval<20):val=determinant(matrixSubtract(scalarMultiply(I3,eigval),A))if(val==0):# |lambda*I - A| = 0lst_eigvals+=[eigval]eigval+=1print(*lst_eigvals,sep='\n')
Python:
Ans: -2 4
@pratyush write a question properly. No one wants to guess that by write values you meant distinct values