public void MatrixPeriodTest() { // Period 1 (idempotent) matrix SquareMatrix A = new SquareMatrix(new double[, ] { { 1.0, 1.0 }, { 0.0, 0.0 } }); SquareMatrix A2 = A.Power(2); Assert.IsTrue(TestUtilities.IsNearlyEqual(A2, A)); // Period 2 (self-inverse) matrix SquareMatrix B = new SquareMatrix(2); B[0, 0] = 0.0; B[0, 1] = 1.0; B[1, 0] = 1.0; B[1, 1] = 0.0; SquareMatrix B3 = B.Power(3); Assert.IsTrue(TestUtilities.IsNearlyEqual(B3, B)); // Period 3 matrix // Use the cyclic permutation matrix of order 3 SquareMatrix C = new SquareMatrix(3); C[0, 1] = 1.0; C[1, 2] = 1.0; C[2, 0] = 1.0; SquareMatrix C4 = C.Power(4); Assert.IsTrue(TestUtilities.IsNearlyEqual(C4, C)); }
public void MatrixPowerSpecialCases() { SquareMatrix A = CreateSquareRandomMatrix(3); // Zero power is identity SquareMatrix A0 = A.Power(0); // One power is self SquareMatrix A1 = A.Power(1); Assert.IsTrue(A == A1); // Two powers same as multiplying by self SquareMatrix A2 = A.Power(2); Assert.IsTrue(TestUtilities.IsNearlyEqual(A2, A * A)); }