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 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)