diff --git a/linalg-practice.py b/linalg-practice.py index 032e0b1..59f663f 100644 --- a/linalg-practice.py +++ b/linalg-practice.py @@ -36,6 +36,16 @@ def invcheck(a, b, rowcol, intmax): print("What is the inverse of this matrix?") return (sp.Matrix(inmat(rowcol)) == a.inv()) +# eigcheck function to check if the eigenvalues are correct +def eigcheck(a, b, rowcol, intmax): + eigs = a.eigenvals() + for i in range(len(eigs)) : + val = sp.nsimplify(input("Input eigenvalue: ")) + if not (val in eigs and eigs[val] == sp.nsimplify(input("Input its algebraic multiplicity: "))) : + # return false if the eigenvalue not in dictionary and wrong alg multiplicity + return False + return True + # practice function def practice(t) : count = 0 @@ -50,6 +60,8 @@ def practice(t) : f = detcheck elif t == "inv" : f = invcheck + elif t == "eig" : + f = eigcheck else : exit()