Beispiel #1
0
        public void TryInvert()
        {
            // Regular, square
              MatrixF m = new MatrixF(new float[,] {{1, 2, 3, 4},
                                            {2, 5, 8, 3},
                                            {7, 6, -1, 1},
                                            {4, 9, 7, 7}});
              MatrixF inverse = m.Clone();
              Assert.AreEqual(true, m.TryInvert());
              Assert.IsTrue(MatrixF.AreNumericallyEqual(MatrixF.CreateIdentity(4, 4), m * inverse));

              // Full column rank, rectangular
              m = new MatrixF(new float[,] {{1, 2, 3},
                                    {2, 5, 8},
                                    {7, 6, -1},
                                    {4, 9, 7}});
              inverse = m.Clone();
              Assert.AreEqual(true, m.TryInvert());
              Assert.IsTrue(MatrixF.AreNumericallyEqual(m, m * inverse * m));

              // singular
              m = new MatrixF(new float[,] {{1, 2, 3},
                                    {2, 5, 8},
                                    {3, 7, 11}});
              inverse = m.Clone();
              Assert.AreEqual(false, m.TryInvert());
        }