Skip to content

Commit

Permalink
Merge pull request #2 from Siddhesh-Agarwal/Siddhesh-Agarwal-patch-1.0.1
Browse files Browse the repository at this point in the history
Update and rename mmath.py to matmath.py
  • Loading branch information
Siddhesh-Agarwal authored Jun 17, 2021
2 parents 05d6f52 + 8c854dc commit 6a761b6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/matmath/mmath.py → src/matmath/matmath.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from warnings import UserWarning
from warnings import showwarning

################################################################################
## Basic Matrices ##
Expand Down Expand Up @@ -34,17 +34,17 @@ def Null(a, n, m = 0):
def compatAS(a, b):
if isMatrix(a) and isMatrix(b):
return False if len(a) != len(b) or len(a[0]) != len(b[0]) else True
UserWarning("Error: The given parameter is not a matrix.")
showwarning("Error: The given parameter is not a matrix.", UserWarning, str, 37)

# Returns True if matrices are compatible for multiplication else returns False.
def compatM(A, B):
if isMatrix(A) and isMatrix(B):
return True if len(A[0]) == len(B) else False
UserWarning("Error: The given parameter is not a matrix.")
showwarning("Error: The given parameter is not a matrix.", UserWarning, str, 43)


################################################################################
## Arithamatic Operations ##
## Arithmetic Operations ##
################################################################################

# Returns the sum matrix (A + B), provided the matrices are compatible.
Expand All @@ -56,7 +56,7 @@ def matAdd(a, b):
for j in range( len(a[i]) ):
matrix[i].append( a[i][j] + b[i][j] )
return matrix
UserWarning( "Error: matrices do not have same order.")
showwarning("Error: matrices do not have same order.", UserWarning, str, 59)

# Returns the difference matrix (A - B), provided the matrices are compatible.
def matSub(a, b):
Expand All @@ -77,7 +77,7 @@ def matMul(a, b):
total += (a[i][k] * b[k][j])
matrix[i].append( total )
return matrix
UserWarning("Error: matrices not compatible for multiplication.")
showwarning("Error: matrices not compatible for multiplication.", UserWarning, str, 80)

# Returns the matrix representing the n^th power of matrix A, provided the matrix is square matrix.
def power(a, n):
Expand All @@ -86,7 +86,7 @@ def power(a, n):
for _ in range( n - 1 ):
matrix = matMul(a, matrix)
return matrix
UserWarning("Error: The given matrix is not square.")
showwarning("Error: The given matrix is not square.", UserWarning, str, 89)

# Returns the scalar product of A and n (nA).
def scalarMul(a, n=1):
Expand Down Expand Up @@ -136,7 +136,7 @@ def adj(A, mul_factor=1):
for j in range(len(A)):
matrix[i].append(float(det(cut(A, i , j))))
return transpose(matrix, mul_factor)
UserWarning("Error: The given matrix is not square.")
showwarning("Error: The given matrix is not square.", UserWarning, str, 139)

# Returns the inverse of the matrix (if and only if the matrices are compatible) multiplied by the multiplication factor. Default value of mul_factor (multiplication factor) is 1.
def inv(A, mul_factor=1):
Expand All @@ -147,7 +147,7 @@ def inv(A, mul_factor=1):
for j in range(len(A)):
matrix[i].append(adj(A, mul_factor)[i][j])
return matrix
UserWarning("Error: The given matrix is not square.")
showwarning("Error: The given matrix is not square.", UserWarning, str, 150)


################################################################################
Expand All @@ -169,7 +169,7 @@ def det(a, mul_factor=1):
for i in range(length):
det *= a[i][i]
return det
UserWarning("Error: The given matrix is not square.")
showwarning("Error: The given matrix is not square.", UserWarning, str, 172)

# Returns the trace of the matrix (i.e the product of elements on the diagonal) if possible.
def trace(A):
Expand Down

0 comments on commit 6a761b6

Please sign in to comment.