diff --git a/linalg-practice.py b/linalg-practice.py index 2b2c8f3..9f7c032 100644 --- a/linalg-practice.py +++ b/linalg-practice.py @@ -54,6 +54,9 @@ def eigcheck(a, b, rowcol, intmax): return False return True +def diagcheck(a, b, rowcol, intmax): + return (a.diagonalize()[1] == sp.Matrix(inmat(rowcol))) + # practice function def practice(t) : count = 0 @@ -70,6 +73,8 @@ def practice(t) : f = invcheck elif t == "eig" : f = eigcheck + elif t == "diag" : + f = diagcheck else : exit() @@ -83,6 +88,10 @@ def practice(t) : # infinite loop until user succeeds while True : + # if diagcheck, make sure the matrix is diagonalizable + if t == "diag" : + while not a.is_diagonalizable : + a = genmatrix(rowcol, intmax, dif) sp.pprint(a) # if return of function is True if f(a, b, rowcol, intmax) : @@ -100,5 +109,5 @@ def practice(t) : continue # take input from user on the type of practice they want to do -t = input("What do you want to practice? (mult, det, inv, eig) ") +t = input("What do you want to practice? (mult, det, inv, eig, diag) ") practice(t)