Ejemplo n.º 1
0
        public void SquareMatrixNotInvertable()
        {
            SquareMatrix A = new SquareMatrix(2);

            A[1, 1] = 1.0;

            // Inverting should throw
            try {
                A.Inverse();
                Assert.IsTrue(false);
            } catch (DivideByZeroException) {
            }

            // LU Decomposing should throw
            try {
                A.LUDecomposition();
                Assert.IsTrue(false);
            } catch (DivideByZeroException) {
            }

            // SVD should succeed, and give infinite condition number
            SingularValueDecomposition SVD = A.SingularValueDecomposition();

            Assert.IsTrue(Double.IsInfinity(SVD.ConditionNumber));
        }
Ejemplo n.º 2
0
 public void SquareVandermondeMatrixInverse()
 {
     for (int d = 1; d < 8; d++)
     {
         SquareMatrix H  = CreateVandermondeMatrix(d);
         SquareMatrix HI = H.Inverse();
         Assert.IsTrue(TestUtilities.IsNearlyEqual(H * HI, UnitMatrix.OfDimension(d)));
     }
 }
Ejemplo n.º 3
0
 public void SquareRandomMatrixInverse()
 {
     for (int d = 1; d <= 100; d = d + 11)
     {
         SquareMatrix M  = CreateSquareRandomMatrix(d, 1);
         SquareMatrix MI = M.Inverse();
         Assert.IsTrue(TestUtilities.IsNearlyEqual(M * MI, UnitMatrix.OfDimension(d)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(MI * M, UnitMatrix.OfDimension(d)));
     }
 }
Ejemplo n.º 4
0
 public void SquareVandermondeMatrixInverse()
 {
     for (int d = 1; d <= 8; d++)
     {
         SquareMatrix I      = TestUtilities.CreateSquareUnitMatrix(d);
         SquareMatrix H      = CreateVandermondeMatrix(d);
         DateTime     start  = DateTime.Now;
         SquareMatrix HI     = H.Inverse();
         DateTime     finish = DateTime.Now;
         Console.WriteLine("d={0} t={1} ms", d, (finish - start).Milliseconds);
         PrintMatrix(HI);
         PrintMatrix(H * HI);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(H * HI, I));
     }
 }
Ejemplo n.º 5
0
        public void Bug7208()
        {
            // this matrix has two eigenpairs with the same eigenvalue but distinct eigenvectors
            // we would report the same eigenvector for both, making the matrix of eigenvectors
            // non-invertible
            int          n      = 4;
            SquareMatrix matrix = new SquareMatrix(n + 1);
            double       d      = (3 + 2 * Math.Cos(2 * Math.PI / n));
            double       w      = (64 * n) / (40 - d * d) - n;
            double       w1     = w / (w + n);
            double       w2     = 1 / (w + n);

            matrix[0, 0] = w1;
            for (int i = 1; i < n; i++)
            {
                matrix[0, i + 1]     = w2;
                matrix[i + 1, 0]     = 3.0 / 8;
                matrix[i + 1, i + 1] = 3.0 / 8;
                matrix[i, i + 1]     = 1.0 / 8;
                matrix[i + 1, i]     = 1.0 / 8;
            }
            matrix[0, 1] = w2;
            matrix[1, 0] = 3.0 / 8;
            matrix[1, 1] = 3.0 / 8;
            matrix[1, n] = 1.0 / 8;
            matrix[n, 1] = 1.0 / 8;

            ComplexEigensystem ces = matrix.Eigensystem();

            Console.WriteLine("output");
            SquareMatrix V = new SquareMatrix(n + 1);

            for (int i = 0; i < n + 1; i++)
            {
                Console.WriteLine("#{0}: {1}", i, ces.Eigenvalue(i));
                for (int j = 0; j < n + 1; j++)
                {
                    V[i, j] = ces.Eigenvector(i)[j].Re;
                    Console.WriteLine(V[i, j]);
                }
            }

            SquareMatrix inv = V.Inverse();
        }