Compare commits
	
		
			No commits in common. "a680f4bbd929f128dd19f8e3da44b1208238cf5c" and "6eb450ddbeb35232082fd6024d37cb22058fa983" have entirely different histories.
		
	
	
		
			a680f4bbd9
			...
			6eb450ddbe
		
	
		
| @ -1,9 +1,6 @@ | |||||||
| import sympy as sp | import sympy as sp | ||||||
| import time | import time | ||||||
| import random | import random | ||||||
| import readline |  | ||||||
| 
 |  | ||||||
| errs = (ValueError, TypeError) |  | ||||||
| 
 | 
 | ||||||
| def genmatrix(rowcol, intmax, dif) : | def genmatrix(rowcol, intmax, dif) : | ||||||
|     # generate a random matrices |     # generate a random matrices | ||||||
| @ -23,11 +20,7 @@ def inmat(rowcol) : | |||||||
|         mat[i]=input().split(" ") |         mat[i]=input().split(" ") | ||||||
|         for j in range(len(mat[i])) : |         for j in range(len(mat[i])) : | ||||||
|             # convert list using nsimplify in order to take rational number symbolically |             # convert list using nsimplify in order to take rational number symbolically | ||||||
|             try : |  | ||||||
|             mat[i][j] = sp.nsimplify(mat[i][j]) |             mat[i][j] = sp.nsimplify(mat[i][j]) | ||||||
|             except errs : return False |  | ||||||
|     try : mat = sp.Matrix(mat) |  | ||||||
|     except errs : return False |  | ||||||
|     return mat |     return mat | ||||||
| 
 | 
 | ||||||
| # multcheck function to check if two matrices are multiplied together | # multcheck function to check if two matrices are multiplied together | ||||||
| @ -35,41 +28,41 @@ def multcheck(a, b, rowcol, intmax) : | |||||||
|     sp.pprint(b) |     sp.pprint(b) | ||||||
|     print("Multiply these two matrices together") |     print("Multiply these two matrices together") | ||||||
|     # return bool based on if input equals the two matrices multiplied together |     # return bool based on if input equals the two matrices multiplied together | ||||||
|     return (inmat(rowcol) == a*b) |     return (sp.Matrix(inmat(rowcol)) == a*b) | ||||||
| 
 | 
 | ||||||
| # detcheck function to check if the determinant of the matrix is correct | # detcheck function to check if the determinant of the matrix is correct | ||||||
| def detcheck(a, b, rowcol, intmax): | def detcheck(a, b, rowcol, intmax): | ||||||
|     det = sp.det(a) |     det = sp.det(a) | ||||||
|     # return bool based on if input equals determinant |     # return bool based on if input equals determinant | ||||||
|     try : d = sp.nsimplify(input("What is the determinant of this matrix?: ")) |     return (det == sp.nsimplify(input("What is the determinant of this matrix?: "))) | ||||||
|     except errs : return False |  | ||||||
|     return (det == d) |  | ||||||
| 
 | 
 | ||||||
| # invcheck function to check if the inverse of the matrix is correct | # invcheck function to check if the inverse of the matrix is correct | ||||||
| def invcheck(a, b, rowcol, intmax): | def invcheck(a, b, rowcol, intmax): | ||||||
|  |     det = a.det() | ||||||
|  |     if det != 0 : | ||||||
|         # return bool based on if input equals inverse of matrix |         # return bool based on if input equals inverse of matrix | ||||||
|         print("What is the inverse of this matrix?") |         print("What is the inverse of this matrix?") | ||||||
|     return (inmat(rowcol) == a.inv()) |         return (sp.Matrix(inmat(rowcol)) == a.inv()) | ||||||
| 
 | 
 | ||||||
| # eigcheck function to check if the eigenvalues are correct | # eigcheck function to check if the eigenvalues are correct | ||||||
| def eigcheck(a, b, rowcol, intmax): | def eigcheck(a, b, rowcol, intmax): | ||||||
|     eigs = a.eigenvals() |     eigs = a.eigenvals() | ||||||
|     for i in range(len(eigs)) : |     for i in range(len(eigs)) : | ||||||
|         try : |  | ||||||
|         val = sp.nsimplify(input("Input eigenvalue: ")) |         val = sp.nsimplify(input("Input eigenvalue: ")) | ||||||
|             algm = sp.nsimplify(input("Input its algebraic multiplicity: ")) |         if not (val in eigs and eigs[val] == sp.nsimplify(input("Input its algebraic multiplicity: "))) : | ||||||
|         except errs : return False |  | ||||||
|         if not (val in eigs and eigs[val] == algm) : |  | ||||||
|             # return false if the eigenvalue not in dictionary and wrong alg multiplicity |             # return false if the eigenvalue not in dictionary and wrong alg multiplicity | ||||||
|             return False |             return False | ||||||
|     return True |     return True | ||||||
| 
 | 
 | ||||||
| def diagcheck(a, b, rowcol, intmax): | def diagcheck(a, b, rowcol, intmax): | ||||||
|     return (a.diagonalize()[1] == inmat(rowcol)) |     return (a.diagonalize()[1] == sp.Matrix(inmat(rowcol))) | ||||||
| 
 | 
 | ||||||
| # practice function | # practice function | ||||||
| def practice(t) : | def practice(t) : | ||||||
|     count = 0 |     count = 0 | ||||||
|  |     rowcol = int(input("What size of matrix do you want to practice with? ")) | ||||||
|  |     intmax = int(input("What maximum size of integer do you want the matrix to be made out of? ")) | ||||||
|  |     dif = float(input("What difficulty (probability for a matrix of rational values between 0, 1) do you want? ")) | ||||||
| 
 | 
 | ||||||
|     # choose the function of the program that you want |     # choose the function of the program that you want | ||||||
|     if t == "mult" : |     if t == "mult" : | ||||||
| @ -85,15 +78,6 @@ def practice(t) : | |||||||
|     else : |     else : | ||||||
|         exit() |         exit() | ||||||
| 
 | 
 | ||||||
|     while True : |  | ||||||
|         try : |  | ||||||
|             rowcol = abs(int(input("What size of matrix do you want to practice with? "))) |  | ||||||
|             intmax = abs(int(input("What maximum size of integer do you want the matrix to be made out of? "))) |  | ||||||
|             dif = float(input("What difficulty (probability for a matrix of rational values between 0, 1) do you want? ")) |  | ||||||
|             break |  | ||||||
|         except errs: |  | ||||||
|             continue |  | ||||||
| 
 |  | ||||||
|     # initialise time measurement |     # initialise time measurement | ||||||
|     tic = time.perf_counter() |     tic = time.perf_counter() | ||||||
| 
 | 
 | ||||||
| @ -108,9 +92,6 @@ def practice(t) : | |||||||
|             if t == "diag" : |             if t == "diag" : | ||||||
|                 while not a.is_diagonalizable : |                 while not a.is_diagonalizable : | ||||||
|                     a = genmatrix(rowcol, intmax, dif) |                     a = genmatrix(rowcol, intmax, dif) | ||||||
|             if t == "inv" : |  | ||||||
|                 while a.det() == 0 : |  | ||||||
|                     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) : | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user