public void UnitMatrixNorms() { UnitMatrix I = UnitMatrix.OfDimension(4); SquareMatrix A = I.ToSquareMatrix(); Assert.IsTrue(I.OneNorm() == A.OneNorm()); Assert.IsTrue(I.InfinityNorm() == A.InfinityNorm()); Assert.IsTrue(I.FrobeniusNorm() == A.FrobeniusNorm()); Assert.IsTrue(I.MaxNorm() == A.MaxNorm()); }
public void SquareMatrixNorms() { SquareMatrix Z = new SquareMatrix(3); Assert.IsTrue(Z.OneNorm() == 0.0); Assert.IsTrue(Z.InfinityNorm() == 0.0); Assert.IsTrue(Z.FrobeniusNorm() == 0.0); Assert.IsTrue(Z.MaxNorm() == 0.0); SquareMatrix A = CreateSquareRandomMatrix(4); Assert.IsTrue(A.OneNorm() > 0.0); Assert.IsTrue(A.InfinityNorm() > 0.0); Assert.IsTrue(A.FrobeniusNorm() > 0.0); Assert.IsTrue(A.MaxNorm() > 0.0); SquareMatrix B = CreateVandermondeMatrix(4); Assert.IsTrue(B.OneNorm() > 0.0); Assert.IsTrue(B.InfinityNorm() > 0.0); Assert.IsTrue(B.FrobeniusNorm() > 0.0); Assert.IsTrue(B.MaxNorm() > 0.0); SquareMatrix S = A + B; Assert.IsTrue(S.OneNorm() <= A.OneNorm() + B.OneNorm()); Assert.IsTrue(S.InfinityNorm() <= A.InfinityNorm() + B.InfinityNorm()); Assert.IsTrue(S.FrobeniusNorm() <= A.FrobeniusNorm() + B.FrobeniusNorm()); Assert.IsTrue(S.MaxNorm() <= A.MaxNorm() + B.MaxNorm()); double t = -1.5; SquareMatrix M = t * A; Assert.IsTrue(TestUtilities.IsNearlyEqual(M.OneNorm(), Math.Abs(t) * A.OneNorm())); Assert.IsTrue(TestUtilities.IsNearlyEqual(M.InfinityNorm(), Math.Abs(t) * A.InfinityNorm())); Assert.IsTrue(TestUtilities.IsNearlyEqual(M.FrobeniusNorm(), Math.Abs(t) * A.FrobeniusNorm())); Assert.IsTrue(TestUtilities.IsNearlyEqual(M.MaxNorm(), Math.Abs(t) * A.MaxNorm())); // Frobenius norm is sub-multiplicative SquareMatrix P = A * B; Assert.IsTrue(P.FrobeniusNorm() <= A.FrobeniusNorm() * B.FrobeniusNorm()); }