Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public void SetElement()
        {
            B.SetElement(ib, jb, 0.0);
            double tmp = B.GetElement(ib, jb);

            Assert.IsTrue(GeneralTests.Check(0.0, tmp));
        }
Ejemplo n.º 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()))));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 8
0
        public void RightDivide()
        {
            A = R.Copy();
            GeneralMatrix C = A.ArrayRightDivide(R);

            Assert.IsTrue(GeneralTests.Check(C, O));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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]));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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())));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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)));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 22
0
 public void SetMatrix4()
 {
     B.SetMatrix(rowindexset, jb, je, M);
     Assert.IsTrue(GeneralTests.Check(M.Subtract(B.GetMatrix(rowindexset, jb, je)), M));
 }
Ejemplo n.º 23
0
        public void MultiplyZero()
        {
            GeneralMatrix Z = new GeneralMatrix(A.RowDimension, A.ColumnDimension);

            Assert.IsTrue(GeneralTests.Check(A.Multiply(0.0), Z));
        }
Ejemplo n.º 24
0
        public void Transpose6()
        {
            A.Transpose();

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