Skip to content

Commit 20295fa

Browse files
committed
Add eigenvale axiom unit test.
1 parent 6072bf2 commit 20295fa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/LinearAlgebra/Eigen/EigenAxiomsTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class EigenAxiomsTest extends \PHPUnit\Framework\TestCase
2424
* - tr(A) = Σλᵢ (trace equals sum of eigenvalues)
2525
* - det(A) = Πλᵢ (determinant equals product of eigenvalues)
2626
* - Aⁿv = λⁿv (matrix power property)
27+
* - Eigenvalues of a triangular matrix are its diagonal entries
2728
*/
2829

2930
/**************************************************************************
@@ -170,6 +171,32 @@ public function testMatrixPowerProperty(array $A, int $n)
170171
}
171172
}
172173

174+
/**
175+
* @test Axiom: Eigenvalues of a triangular matrix are its diagonal entries
176+
* For a triangular matrix (upper or lower), its eigenvalues are simply the entries on its main diagonal.
177+
*
178+
* @dataProvider dataProviderForUpperTriangularMatrix
179+
* @dataProvider dataProviderForLowerTriangularMatrix
180+
* @param array $A
181+
* @throws \Exception
182+
*/
183+
public function testEigenvaluesOfTriangularMatrixAreDiagonalEntries(array $A)
184+
{
185+
// Given
186+
$A = MatrixFactory::create($A);
187+
188+
// When
189+
$eigenvalues = $A->eigenvalues();
190+
$diagonal = $A->getDiagonalElements();
191+
192+
// And
193+
sort($eigenvalues);
194+
sort($diagonal);
195+
196+
// Then
197+
$this->assertEqualsWithDelta($diagonal, $eigenvalues, 1e-6);
198+
}
199+
173200
/**************************************************************************
174201
* DATA PROVIDERS FOR EIGENVALUE TESTS
175202
**************************************************************************/

0 commit comments

Comments
 (0)