Determinant of Matrix¶
- linear_determinant(matrix, result=0)¶
Calculate the determinant of a matrix
- Parameters
matrix (list of lists of int or float) – List of lists of numbers representing a matrix
- Raises
TypeError – First argument must be a 2-dimensional list
TypeError – Elements nested within first argument must be integers or floats
ValueError – First argument must contain the same amount of lists as the amount of elements contained within its first list
- Returns
determinant – Determinant of a matrix
- Return type
float
Warning
Function has factorial time complexity; not recommended for matrices larger than 7-by-7
See also
Notes
Original matrix: \(\mathbf{A} = \begin{bmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,j} & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,j} & a_{2,n} \\ a_{i,1} & a_{i,2} & \cdots & a_{i,j} & a_{i,n} \\ \cdots & \cdots & \cdots & \cdots & \cdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,j} & a_{m,n} \end{bmatrix}\)
Determinant of matrix (if \(\mathbf{A}\) contains an odd number of columns): \(|\mathbf{A}| = a_{1,1}\cdot{|\mathbf{A}_{1,1}|} - a_{1,2}\cdot{|\mathbf{A}_{1,2}|} + \cdots - a_{1,j}\cdot{|\mathbf{A}_{1,j}|} + a_{1,n}\cdot{|\mathbf{A}_{1,n}|}\)
Determinant of matrix (if \(\mathbf{A}\) contains an even number of columns): \(|\mathbf{A}| = a_{1,1}\cdot{|\mathbf{A}_{1,1}|} - a_{1,2}\cdot{|\mathbf{A}_{1,2}|} + \cdots + a_{1,j}\cdot{|\mathbf{A}_{1,j}|} - a_{1,n}\cdot{|\mathbf{A}_{1,n}|}\)
Examples
- Import linear_determinant function from regressions library
>>> from regressions.matrices.determinant import linear_determinant
- Calculate the determinant of [[1, 2], [3, 4]]
>>> determinant_2x2 = linear_determinant([[1, 2], [3, 4]]) >>> print(determinant_2x2) -2.0
- Calculate the determinant of [[2, 3, 5], [7, 11, 13], [17, 19, 23]]
>>> determinant_3x3 = linear_determinant([[2, 3, 5], [7, 11, 13], [17, 19, 23]]) >>> print(determinant_3x3) -78.0