예제 #1
0
        public void DEF()
        {
            double[][]    rankdef = { new double[] { 1.0, 4.0, 7.0, 10.0 }, new double[] { 2.0, 5.0, 8.0, 11.0 }, new double[] { 3.0, 6.0, 9.0, 12.0 } };
            GeneralMatrix def     = new GeneralMatrix(rankdef);

            Assert.IsTrue(GeneralTests.Check(def.Rank(), System.Math.Min(def.RowDimension, def.ColumnDimension) - 1));
        }
예제 #2
0
        public void SetElement()
        {
            B.SetElement(ib, jb, 0.0);
            double tmp = B.GetElement(ib, jb);

            Assert.IsTrue(GeneralTests.Check(0.0, tmp));
        }
예제 #3
0
        public void SingularValueDecomposition()
        {
            GeneralMatrix A = new GeneralMatrix(columnwise, 4);
            SingularValueDecomposition SVD = A.SVD();

            Assert.IsTrue(GeneralTests.Check(A, SVD.GetU().Multiply(SVD.S.Multiply(SVD.GetV().Transpose()))));
        }
예제 #4
0
        public void MultiplyTranspose()
        {
            double[][]    square = { new double[] { 166.0, 188.0, 210.0 }, new double[] { 188.0, 214.0, 240.0 }, new double[] { 210.0, 240.0, 270.0 } };
            GeneralMatrix sq     = new GeneralMatrix(square);

            Assert.IsTrue(GeneralTests.Check(A.Multiply(A.Transpose()), sq));
        }
예제 #5
0
        public void SetSubMatrix()
        {
            B.SetMatrix(ib, ie, jb, je, SUB);
            GeneralMatrix NewSub = B.GetMatrix(ib, ie, jb, je);

            Assert.IsTrue(GeneralTests.Check(SUB, NewSub));
        }
예제 #6
0
        public void SubstractAndAdd()
        {
            GeneralMatrix B = GeneralMatrix.Random(A.RowDimension, A.ColumnDimension);
            GeneralMatrix C = A.Subtract(B);

            Assert.IsTrue(GeneralTests.Check(C.Add(B), A));
        }
예제 #7
0
        public void Inverse()
        {
            GeneralMatrix r  = GeneralMatrix.Random(4, 4);
            GeneralMatrix iR = r.Inverse();

            Assert.IsTrue(GeneralTests.Check(r.Multiply(iR), GeneralMatrix.Identity(4, 4)));
        }
예제 #8
0
        public void RightDivide()
        {
            A = R.Copy();
            GeneralMatrix C = A.ArrayRightDivide(R);

            Assert.IsTrue(GeneralTests.Check(C, O));
        }
예제 #9
0
        public void ArrayMultiplyEquals()
        {
            A = R.Copy();
            GeneralMatrix B = GeneralMatrix.Random(A.RowDimension, A.ColumnDimension);

            A.ArrayMultiplyEquals(B);
            Assert.IsTrue(GeneralTests.Check(A.ArrayRightDivideEquals(B), R));
        }
예제 #10
0
        public void SetMatrix3()
        {
            B.SetMatrix(ib, ie, jb, je, SUB);

            GeneralMatrix C = B.GetMatrix(ib, ie, jb, je);

            Assert.IsTrue(GeneralTests.Check(C, SUB));
        }
예제 #11
0
        public void SingularValues()
        {
            double[][]    condmat          = { new double[] { 1.0, 3.0 }, new double[] { 7.0, 9.0 } };
            GeneralMatrix B                = new GeneralMatrix(condmat);
            SingularValueDecomposition SVD = B.SVD();

            double[] singularvalues = SVD.SingularValues;
            Assert.IsTrue(GeneralTests.Check(B.Condition(), singularvalues[0] / singularvalues[System.Math.Min(B.RowDimension, B.ColumnDimension) - 1]));
        }
예제 #12
0
        public void QRDecomposition()
        {
            GeneralMatrix A = new GeneralMatrix(columnwise, 4);

            QRDecomposition QR = A.QRD();
            GeneralMatrix   R  = QR.R;

            Assert.IsTrue(GeneralTests.Check(A, QR.Q.Multiply(R)));
        }
예제 #13
0
        public void CholeskyDecomposition2()
        {
            double[][]            pvals = { new double[] { 1.0, 1.0, 1.0 }, new double[] { 1.0, 2.0, 3.0 }, new double[] { 1.0, 3.0, 6.0 } };
            GeneralMatrix         A     = new GeneralMatrix(pvals);
            CholeskyDecomposition chol  = A.chol();
            GeneralMatrix         X     = chol.Solve(GeneralMatrix.Identity(3, 3));

            Assert.IsTrue(GeneralTests.Check(A.Multiply(X), GeneralMatrix.Identity(3, 3)));
        }
예제 #14
0
        public void CholeskyDecomposition1()
        {
            double[][]            pvals = { new double[] { 1.0, 1.0, 1.0 }, new double[] { 1.0, 2.0, 3.0 }, new double[] { 1.0, 3.0, 6.0 } };
            GeneralMatrix         A     = new GeneralMatrix(pvals);
            CholeskyDecomposition chol  = A.chol();
            GeneralMatrix         L     = chol.GetL();

            Assert.IsTrue(GeneralTests.Check(A, L.Multiply(L.Transpose())));
        }
예제 #15
0
        public void EigenValueDecomposition2()
        {
            double[][]              evals = { new double[] { 0.0, 1.0, 0.0, 0.0 }, new double[] { 1.0, 0.0, 2e-7, 0.0 }, new double[] { 0.0, -2e-7, 0.0, 1.0 }, new double[] { 0.0, 0.0, 1.0, 0.0 } };
            GeneralMatrix           A     = new GeneralMatrix(evals);
            EigenvalueDecomposition Eig   = A.Eigen();
            GeneralMatrix           D     = Eig.D;
            GeneralMatrix           V     = Eig.GetV();

            Assert.IsTrue(GeneralTests.Check(A.Multiply(V), V.Multiply(D)));
        }
예제 #16
0
        public void LUDecomposition()
        {
            GeneralMatrix A = new GeneralMatrix(columnwise, 4);
            int           n = A.ColumnDimension;

            A = A.GetMatrix(0, n - 1, 0, n - 1);
            A.SetElement(0, 0, 0.0);
            LUDecomposition LU = A.LUD();

            Assert.IsTrue(GeneralTests.Check(A.GetMatrix(LU.Pivot, 0, n - 1), LU.L.Multiply(LU.U)));
        }
예제 #17
0
        public void SolveLinear()
        {
            double[][]    subavals   = { new double[] { 5.0, 8.0, 11.0 }, new double[] { 6.0, 9.0, 12.0 } };
            double[][]    sqSolution = { new double[] { 13.0 }, new double[] { 15.0 } };
            GeneralMatrix sub        = new GeneralMatrix(subavals);
            GeneralMatrix o          = new GeneralMatrix(sub.RowDimension, 1, 1.0);
            GeneralMatrix sol        = new GeneralMatrix(sqSolution);
            GeneralMatrix sq         = sub.GetMatrix(0, sub.RowDimension - 1, 0, sub.RowDimension - 1);

            Assert.IsTrue(GeneralTests.Check(sq.Solve(sol), o));
        }
예제 #18
0
        public void SubMatrixWithRowIndexSetColumnIndexSet()
        {
            double[][] avals          = { new double[] { 1.0, 4.0, 7.0, 10.0 }, new double[] { 2.0, 5.0, 8.0, 11.0 }, new double[] { 3.0, 6.0, 9.0, 12.0 } };
            double[][] subavals       = { new double[] { 5.0, 8.0, 11.0 }, new double[] { 6.0, 9.0, 12.0 } };
            int[]      rowindexset    = new int[] { 1, 2 };
            int[]      columnindexset = new int[] { 1, 2, 3 };

            GeneralMatrix B = new GeneralMatrix(avals);

            M   = B.GetMatrix(rowindexset, columnindexset);
            SUB = new GeneralMatrix(subavals);

            Assert.IsTrue(GeneralTests.Check(SUB, M));
        }
예제 #19
0
        public void SubMatrixWithColumnIndex()
        {
            int ib = 1, ie = 2;             /* index ranges for sub GeneralMatrix */

            double[][] avals    = { new double[] { 1.0, 4.0, 7.0, 10.0 }, new double[] { 2.0, 5.0, 8.0, 11.0 }, new double[] { 3.0, 6.0, 9.0, 12.0 } };
            double[][] subavals = { new double[] { 5.0, 8.0, 11.0 }, new double[] { 6.0, 9.0, 12.0 } };

            GeneralMatrix B = new GeneralMatrix(avals);

            M   = B.GetMatrix(ib, ie, columnindexset);
            SUB = new GeneralMatrix(subavals);

            Assert.IsTrue(GeneralTests.Check(SUB, M));
        }
예제 #20
0
        public void SubMatrixWithRowIndexSet()
        {
            int jb = 1, je = 3;             /* index ranges for sub GeneralMatrix */

            double[][] avals       = { new double[] { 1.0, 4.0, 7.0, 10.0 }, new double[] { 2.0, 5.0, 8.0, 11.0 }, new double[] { 3.0, 6.0, 9.0, 12.0 } };
            double[][] subavals    = { new double[] { 5.0, 8.0, 11.0 }, new double[] { 6.0, 9.0, 12.0 } };
            int[]      rowindexset = new int[] { 1, 2 };

            GeneralMatrix B = new GeneralMatrix(avals);

            M   = B.GetMatrix(rowindexset, jb, je);
            SUB = new GeneralMatrix(subavals);

            Assert.IsTrue(GeneralTests.Check(SUB, M));
        }
예제 #21
0
 public void SetMatrix1()
 {
     B.SetMatrix(ib, ie, jb, je, M);
     Assert.IsTrue(GeneralTests.Check(M.Subtract(B.GetMatrix(ib, ie, jb, je)), M));
 }
예제 #22
0
 public void SetMatrix4()
 {
     B.SetMatrix(rowindexset, jb, je, M);
     Assert.IsTrue(GeneralTests.Check(M.Subtract(B.GetMatrix(rowindexset, jb, je)), M));
 }
예제 #23
0
        public void MultiplyZero()
        {
            GeneralMatrix Z = new GeneralMatrix(A.RowDimension, A.ColumnDimension);

            Assert.IsTrue(GeneralTests.Check(A.Multiply(0.0), Z));
        }
예제 #24
0
        public void Transpose6()
        {
            A.Transpose();

            Assert.IsTrue(GeneralTests.Check(A.GetMatrix(0, A.RowDimension - 1, 0, A.RowDimension - 1).Determinant(), 0.0));
        }
예제 #25
0
 public void Transpose4()
 {
     A.Transpose();
     Assert.IsTrue(GeneralTests.Check(A.NormF(), System.Math.Sqrt(sumofsquares)));
 }
예제 #26
0
 public void Transpose3()
 {
     A.Transpose();
     Assert.IsTrue(GeneralTests.Check(A.NormInf(), rowsummax));
 }
예제 #27
0
 public void Transpose2()
 {
     A.Transpose();
     Assert.IsTrue(GeneralTests.Check(A.Norm1(), columnsummax));
 }
예제 #28
0
 public void Transpose1()
 {
     T = A.Transpose();
     Assert.IsTrue(GeneralTests.Check(A.Transpose(), T));
 }
예제 #29
0
 public void SetMatrix2()
 {
     B.SetMatrix(ib, ie, columnindexset, M);
     Assert.IsTrue(GeneralTests.Check(M.Subtract(B.GetMatrix(ib, ie, columnindexset)), M));
 }
예제 #30
0
 public void Transpose5()
 {
     A.Transpose();
     Assert.IsTrue(GeneralTests.Check(A.Trace(), sumofdiagonals));
 }