|
14 | 14 |
|
15 | 15 | def determinant_recursive(matrix: NDArray[float64]) -> float: |
16 | 16 | """ |
17 | | - Calculate the determinant of a square matrix using recursive cofactor expansion. |
18 | | -
|
19 | | - This method is suitable for small matrices but becomes inefficient for large matrices. |
20 | | -
|
| 17 | + Calculate the determinant of a square matrix |
| 18 | + using recursive cofactor expansion. |
| 19 | + This method is suitable for |
| 20 | + small matrices but becomes inefficient for large matrices. |
21 | 21 | Parameters: |
22 | 22 | matrix (NDArray[float64]): A square matrix |
23 | | -
|
24 | 23 | Returns: |
25 | 24 | float: The determinant of the matrix |
26 | | -
|
27 | 25 | Raises: |
28 | 26 | ValueError: If the matrix is not square |
29 | | -
|
30 | 27 | Examples: |
31 | 28 | >>> import numpy as np |
32 | 29 | >>> matrix = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=float) |
@@ -65,15 +62,12 @@ def determinant_recursive(matrix: NDArray[float64]) -> float: |
65 | 62 | def determinant_lu(matrix: NDArray[float64]) -> float: |
66 | 63 | """ |
67 | 64 | Calculate the determinant using LU decomposition. |
68 | | -
|
69 | | - This method is more efficient for larger matrices than recursive expansion. |
70 | | -
|
| 65 | + This method is more efficient for larger matrices |
| 66 | + than recursive expansion. |
71 | 67 | Parameters: |
72 | 68 | matrix (NDArray[float64]): A square matrix |
73 | | -
|
74 | 69 | Returns: |
75 | 70 | float: The determinant of the matrix |
76 | | -
|
77 | 71 | Raises: |
78 | 72 | ValueError: If the matrix is not square |
79 | 73 | """ |
@@ -125,16 +119,14 @@ def determinant_lu(matrix: NDArray[float64]) -> float: |
125 | 119 |
|
126 | 120 | def determinant(matrix: NDArray[float64]) -> float: |
127 | 121 | """ |
128 | | - Calculate the determinant of a square matrix using the most appropriate method. |
129 | | -
|
130 | | - Uses recursive expansion for small matrices (≤3x3) and LU decomposition for larger ones. |
131 | | -
|
| 122 | + Calculate the determinant of a square matrix using |
| 123 | + the most appropriate method. |
| 124 | + Uses recursive expansion for small matrices (≤3x3) |
| 125 | + and LU decomposition for larger ones. |
132 | 126 | Parameters: |
133 | 127 | matrix (NDArray[float64]): A square matrix |
134 | | -
|
135 | 128 | Returns: |
136 | 129 | float: The determinant of the matrix |
137 | | -
|
138 | 130 | Examples: |
139 | 131 | >>> import numpy as np |
140 | 132 | >>> matrix = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=float) |
|
0 commit comments