MatrixMath: This class can perform many different mathematical operations on matrixes.
Ejemplo n.º 1
0
        public void Copy()
        {
            double[][] data =
            {
                new[] { 1.0, 2.0 },
                new[] { 3.0, 4.0 }
            };
            var source = new Matrix(data);
            var target = new Matrix(2, 2);

            MatrixMath.Copy(source, target);
            Assert.IsTrue(source.Equals(target));
        }
Ejemplo n.º 2
0
        public void Inverse()
        {
            double[][] matrixData1 =
            {
                new[] { 1.0, 2.0, 3.0, 4.0 }
            };
            double[][] matrixData2 =
            {
                new[] { 1.0 },
                new[] { 2.0 },
                new[] { 3.0 },
                new[] { 4.0 }
            };

            var matrix1     = new Matrix(matrixData1);
            var checkMatrix = new Matrix(matrixData2);

            Matrix matrix2 = MatrixMath.Transpose(matrix1);

            Assert.IsTrue(matrix2.Equals(checkMatrix));
        }
Ejemplo n.º 3
0
        public void Identity()
        {
            try
            {
                MatrixMath.Identity(0);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }

            double[][] checkData =
            {
                new[] { 1.0, 0.0 },
                new[] { 0.0, 1.0 }
            };
            var    check  = new Matrix(checkData);
            Matrix matrix = MatrixMath.Identity(2);

            Assert.IsTrue(check.Equals(matrix));
        }
Ejemplo n.º 4
0
        public void VerifySame()
        {
            double[][] dataBase =
            {
                new[] { 1.0, 2.0 },
                new[] { 3.0, 4.0 }
            };
            double[][] dataTooManyRows =
            {
                new[] { 1.0, 2.0 },
                new[] { 3.0, 4.0 },
                new[] { 5.0, 6.0 }
            };
            double[][] dataTooManyCols =
            {
                new[] { 1.0, 2.0, 3.0 },
                new[] { 4.0, 5.0, 6.0 }
            };
            var baseMatrix  = new Matrix(dataBase);
            var tooManyRows = new Matrix(dataTooManyRows);
            var tooManyCols = new Matrix(dataTooManyCols);

            MatrixMath.Add(baseMatrix, baseMatrix);
            try
            {
                MatrixMath.Add(baseMatrix, tooManyRows);
                Assert.IsFalse(true);
            }
            catch (MatrixError)
            {
            }
            try
            {
                MatrixMath.Add(baseMatrix, tooManyCols);
                Assert.IsFalse(true);
            }
            catch (MatrixError)
            {
            }
        }
Ejemplo n.º 5
0
        public void DeleteRow()
        {
            double[][] origData =
            {
                new[] { 1.0, 2.0 },
                new[] { 3.0, 4.0 }
            };
            double[][] checkData = { new[] { 3.0, 4.0 } };
            var        orig      = new Matrix(origData);
            Matrix     matrix    = MatrixMath.DeleteRow(orig, 0);
            var        check     = new Matrix(checkData);

            Assert.IsTrue(check.Equals(matrix));

            try
            {
                MatrixMath.DeleteRow(orig, 10);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }
        }