added diagcheck feature

This commit is contained in:
Lukasz M 2022-03-31 13:06:36 +02:00
parent 5b7c29a262
commit 6eb450ddbe

View File

@ -54,6 +54,9 @@ def eigcheck(a, b, rowcol, intmax):
return False return False
return True return True
def diagcheck(a, b, rowcol, intmax):
return (a.diagonalize()[1] == sp.Matrix(inmat(rowcol)))
# practice function # practice function
def practice(t) : def practice(t) :
count = 0 count = 0
@ -70,6 +73,8 @@ def practice(t) :
f = invcheck f = invcheck
elif t == "eig" : elif t == "eig" :
f = eigcheck f = eigcheck
elif t == "diag" :
f = diagcheck
else : else :
exit() exit()
@ -83,6 +88,10 @@ def practice(t) :
# infinite loop until user succeeds # infinite loop until user succeeds
while True : 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) sp.pprint(a)
# if return of function is True # if return of function is True
if f(a, b, rowcol, intmax) : if f(a, b, rowcol, intmax) :
@ -100,5 +109,5 @@ def practice(t) :
continue continue
# take input from user on the type of practice they want to do # 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) practice(t)