当前位置: 首页>>代码示例>>C#>>正文


C# DenseMatrix.Subtract方法代码示例

本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.Subtract方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.Subtract方法的具体用法?C# DenseMatrix.Subtract怎么用?C# DenseMatrix.Subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MathNet.Numerics.LinearAlgebra.Double.DenseMatrix的用法示例。


在下文中一共展示了DenseMatrix.Subtract方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run


//.........这里部分代码省略.........
            Console.WriteLine(@"Multiply vector by matrix using method LeftMultiply. (A.LeftMultiply(vec, vec))");
            Console.WriteLine(vector.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Multiply matrix by matrix
            // 1. Using operator "*"
            resultM = matrixA * matrixB;
            Console.WriteLine(@"Multiply matrix by matrix using operator *. (result = A * B)");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using Multiply method and getting result into different matrix instance
            resultM = (DenseMatrix)matrixA.Multiply(matrixB);
            Console.WriteLine(@"Multiply matrix by matrix using method Multiply. (result = A.Multiply(B))");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 3. Using Multiply method and updating matrix itself
            matrixA.Multiply(matrixB, matrixA);
            Console.WriteLine(@"Multiply matrix by matrix using method Multiply. (A.Multiply(B, A))");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Pointwise multiplies matrix with another matrix
            // 1. Using PointwiseMultiply method and getting result into different matrix instance
            resultM = (DenseMatrix)matrixA.PointwiseMultiply(matrixB);
            Console.WriteLine(@"Pointwise multiplies matrix with another matrix using method PointwiseMultiply. (result = A.PointwiseMultiply(B))");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using PointwiseMultiply method and updating matrix itself
            matrixA.PointwiseMultiply(matrixB, matrixA);
            Console.WriteLine(@"Pointwise multiplies matrix with another matrix using method PointwiseMultiply. (A.PointwiseMultiply(B, A))");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Pointwise divide matrix with another matrix
            // 1. Using PointwiseDivide method and getting result into different matrix instance
            resultM = (DenseMatrix)matrixA.PointwiseDivide(matrixB);
            Console.WriteLine(@"Pointwise divide matrix with another matrix using method PointwiseDivide. (result = A.PointwiseDivide(B))");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using PointwiseDivide method and updating matrix itself
            matrixA.PointwiseDivide(matrixB, matrixA);
            Console.WriteLine(@"Pointwise divide matrix with another matrix using method PointwiseDivide. (A.PointwiseDivide(B, A))");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Addition
            // 1. Using operator "+"
            resultM = matrixA + matrixB;
            Console.WriteLine(@"Add matrices using operator +. (result = A + B)");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using Add method and getting result into different matrix instance
            resultM = (DenseMatrix)matrixA.Add(matrixB);
            Console.WriteLine(@"Add matrices using method Add. (result = A.Add(B))");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 3. Using Add method and updating matrix itself
            matrixA.Add(matrixB, matrixA);
            Console.WriteLine(@"Add matrices using method Add. (A.Add(B, A))");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Subtraction
            // 1. Using operator "-"
            resultM = matrixA - matrixB;
            Console.WriteLine(@"Subtract matrices using operator -. (result = A - B)");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using Subtract method and getting result into different matrix instance
            resultM = (DenseMatrix)matrixA.Subtract(matrixB);
            Console.WriteLine(@"Subtract matrices using method Subtract. (result = A.Subtract(B))");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 3. Using Subtract method and updating matrix itself
            matrixA.Subtract(matrixB, matrixA);
            Console.WriteLine(@"Subtract matrices using method Subtract. (A.Subtract(B, A))");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Divide by scalar
            // 1. Using Divide method and getting result into different matrix instance
            resultM = (DenseMatrix)matrixA.Divide(3.0);
            Console.WriteLine(@"Divide matrix by scalar using method Divide. (result = A.Divide(3.0))");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using Divide method and updating matrix itself
            matrixA.Divide(3.0, matrixA);
            Console.WriteLine(@"Divide matrix by scalar using method Divide. (A.Divide(3.0, A))");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();
        }
开发者ID:JohnnyPP,项目名称:TMP102,代码行数:101,代码来源:MatrixArithmeticOperations.cs

示例2: CanSubtractSparseMatricesBothWays

        public void CanSubtractSparseMatricesBothWays()
        {
            var m1 = new SparseMatrix(1, 3);
            var m2 = SparseMatrix.OfArray(new double[,] { { 0, 1, 1 } });
            var diff1 = m1 - m2;
            var diff2 = m2 - m1;
            Assert.IsTrue(diff1.Equals(m2.Negate()));
            Assert.IsTrue(diff1.Equals(diff2.Negate()));

            var sparseResult = new SparseMatrix(1, 3);
            sparseResult.Subtract(m2, sparseResult);
            Assert.IsTrue(sparseResult.Equals(diff1));

            sparseResult = SparseMatrix.OfArray(new double[,] { { 0, 1, 1 } });
            sparseResult.Subtract(m1, sparseResult);
            Assert.IsTrue(sparseResult.Equals(diff2));

            sparseResult = SparseMatrix.OfArray(new double[,] { { 0, 1, 1 } });
            m1.Subtract(sparseResult, sparseResult);
            Assert.IsTrue(sparseResult.Equals(diff1));

            sparseResult = SparseMatrix.OfArray(new double[,] { { 0, 1, 1 } });
            sparseResult.Subtract(sparseResult, sparseResult);
            Assert.IsTrue(sparseResult.Equals(0*diff1));

            var denseResult = new DenseMatrix(1, 3);
            denseResult.Subtract(m2, denseResult);
            Assert.IsTrue(denseResult.Equals(diff1));

            denseResult = DenseMatrix.OfArray(new double[,] {{0, 1, 1}});
            denseResult.Subtract(m1, denseResult);
            Assert.IsTrue(denseResult.Equals(diff2));

            var m3 = DenseMatrix.OfArray(new double[,] {{0, 1, 1}});
            var diff3 = m1 - m3;
            var diff4 = m3 - m1;
            Assert.IsTrue(diff3.Equals(m3.Negate()));
            Assert.IsTrue(diff3.Equals(diff4.Negate()));
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:39,代码来源:SparseMatrixTests.cs


注:本文中的MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.Subtract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。