|
48 | 48 | * - Determinant |
49 | 49 | * - det(A) = det(Aᵀ) |
50 | 50 | * - det(AB) = det(A)det(B) |
| 51 | + * - A is invertible if and only if det A ≠ 0 |
| 52 | + * - A is not invertible if det A = 0 |
| 53 | + * - A is triangular, det(A) is product of entries on main diagonal |
51 | 54 | * - LU Decomposition (PA = LU) |
52 | 55 | * - PA = LU |
53 | 56 | * - A = P⁻¹LU |
@@ -1240,6 +1243,74 @@ public function testDeterminantProductSameAsProductOfDeterminants(array $A, arra |
1240 | 1243 | $this->assertEqualsWithDelta($det⟮AB⟯, $det⟮A⟯det⟮B⟯, 0.000001); |
1241 | 1244 | } |
1242 | 1245 |
|
| 1246 | + |
| 1247 | + /** |
| 1248 | + * @test Axiom: A is invertible if and only if det A ≠ 0 |
| 1249 | + * |
| 1250 | + * @dataProvider dataProviderForNonsingularMatrix |
| 1251 | + * @param array $A |
| 1252 | + * @throws \Exception |
| 1253 | + */ |
| 1254 | + public function testMatrixInvertibleIfAndOnlyIfDetANotEqualsZero(array $A) |
| 1255 | + { |
| 1256 | + // Given |
| 1257 | + $A = MatrixFactory::create($A); |
| 1258 | + |
| 1259 | + // When |
| 1260 | + $det⟮A⟯ = $A->det(); |
| 1261 | + $isInvertible = $A->isInvertible(); |
| 1262 | + |
| 1263 | + // Then |
| 1264 | + $this->assertNotEquals(0, $det⟮A⟯); |
| 1265 | + $this->assertTrue($isInvertible); |
| 1266 | + } |
| 1267 | + |
| 1268 | + /** |
| 1269 | + * @test Axiom: A is not invertible if det A = 0 |
| 1270 | + * |
| 1271 | + * @dataProvider dataProviderForSingularMatrix |
| 1272 | + * @param array $A |
| 1273 | + * @throws \Exception |
| 1274 | + */ |
| 1275 | + public function testMatrixNotInvertibleIfDetEqualsZero(array $A) |
| 1276 | + { |
| 1277 | + // Given |
| 1278 | + $A = MatrixFactory::create($A); |
| 1279 | + |
| 1280 | + // When |
| 1281 | + $det⟮A⟯ = $A->det(); |
| 1282 | + $isInvertible = $A->isInvertible(); |
| 1283 | + |
| 1284 | + // Then |
| 1285 | + $this->assertEquals(0, $det⟮A⟯); |
| 1286 | + $this->assertFalse($isInvertible); |
| 1287 | + } |
| 1288 | + |
| 1289 | + /** |
| 1290 | + * @test Axiom: A is triangular, det(A) is product of entries on main diagonal |
| 1291 | + * |
| 1292 | + * @dataProvider dataProviderForUpperTriangularMatrix |
| 1293 | + * @param array $A |
| 1294 | + * @throws \Exception |
| 1295 | + */ |
| 1296 | + public function testAIsTriangularDetAIsProductOfEntriesOnMainDiagonal(array $A) |
| 1297 | + { |
| 1298 | + // Given |
| 1299 | + $A = MatrixFactory::create($A); |
| 1300 | + |
| 1301 | + // When |
| 1302 | + $det⟮A⟯ = $A->det(); |
| 1303 | + |
| 1304 | + // And |
| 1305 | + $product = 1; |
| 1306 | + for ($i = 0; $i < $A->getM(); $i++) { |
| 1307 | + $product *= $A[$i][$i]; |
| 1308 | + } |
| 1309 | + |
| 1310 | + // Then |
| 1311 | + $this->assertEquals($det⟮A⟯, $product); |
| 1312 | + } |
| 1313 | + |
1243 | 1314 | /** |
1244 | 1315 | * @test Axiom: PA = LU |
1245 | 1316 | * Basic LU decomposition property that permutation matrix times the matrix is the product of the lower and upper decomposition matrices. |
|
0 commit comments