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

            Assert.IsTrue(GeneralTests.Check(0.0, tmp));
        }
        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()))));
        }
        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));
        }
Exemple #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));
        }
        public void SubstractAndAdd()
        {
            GeneralMatrix B = GeneralMatrix.Random(A.RowDimension, A.ColumnDimension);
            GeneralMatrix C = A.Subtract(B);

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

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

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

            Assert.IsTrue(GeneralTests.Check(A.Multiply(0.0), Z));
        }
        public void Transpose6()
        {
            A.Transpose();

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