A Python library adding support for basic Linear Algebra and Analytic Geometry operations
from algebracha import Matrix
matrix = Matrix('1 2 3, 4 5 6')
Matrix's constructor requires one string argument that defines the actual matrix:
EG: to create the following matrix:
1 | 2 | 3 | 4 |
---|---|---|---|
5 | 6 | 7 | 8 |
The argument string must be:
'1 2 3 4, 5 6 7 8'
# or
'''
1 2 3 4,
5 6 7 8
'''
matrix = Matrix('1 2 3, 4 5 6, 7 8 9)
matrix.determinant()
matrix.isSquare()
matrix.isDiagonal()
otherMatrix = Matrix('1 2, 3 4')
matrix.equals(otherMatrix)
matrix.transpose()
otherMatrix = Matrix('1 2, 3 4')
matrix.sum(otherMatrix)
otherMatrix = Matrix('1 2, 3 4, 5 6, 7 8')
matrix.sum(otherMatrix)
matrix.swapRows(1, 2) #row count starts at 1
matrix.swapColumns(1, 2) #column count starts at 1
matrix.sumRows(1, 2) #row 1 becomes the sum of row 1 and row 2
matrix.sumRows(1, 2, 2) #row 1 becomes the sum of row 1 and row 2 multiplied by 2
matrix.sumColumns(1, 2) #column 1 becomes the sum of column 1 and column 2
matrix.sumColumns(1, 2, 2) #column 1 becomes the sum of column 1 and column 2 multiplied by 2
matrix.multiplyRow(1, 3)
matrix.multiplyColumn(2, 4)
matrix.rank()
matrix.transformEchelon()
3 | -5 | 1 | 0 |
---|---|---|---|
3 | 6 | -5 | 1 |
2 | -7 | 4 | 4 |
matrix = Matrix('''
3 -5 1 0,
3 6 -5 1,
2 -7 4 4
''')
matrix.solveSystem()
returns array of solutions: [x, y, z]
[1.348, 0.515, 1.227]
matrix.getInverse()