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


C# DenseMatrix.LeftMultiply方法代码示例

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


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

示例1: Run

        /// <summary>
        /// Run example
        /// </summary>
        /// <seealso cref="http://en.wikipedia.org/wiki/Matrix_multiplication#Scalar_multiplication">Multiply matrix by scalar</seealso>
        /// <seealso cref="http://reference.wolfram.com/mathematica/tutorial/MultiplyingVectorsAndMatrices.html">Multiply matrix by vector</seealso>
        /// <seealso cref="http://en.wikipedia.org/wiki/Matrix_multiplication#Matrix_product">Multiply matrix by matrix</seealso>
        /// <seealso cref="http://en.wikipedia.org/wiki/Matrix_multiplication#Hadamard_product">Pointwise multiplies matrix with another matrix</seealso>
        /// <seealso cref="http://en.wikipedia.org/wiki/Matrix_%28mathematics%29#Basic_operations">Addition and subtraction</seealso>
        public void Run()
        {
            // Initialize IFormatProvider to print matrix/vector data
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            formatProvider.TextInfo.ListSeparator = " ";

            // Create matrix "A"
            var matrixA = new DenseMatrix(new[,] { { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 }, { 7.0, 8.0, 9.0 } });
            Console.WriteLine(@"Matrix A");
            Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Create matrix "B"
            var matrixB = new DenseMatrix(new[,] { { 1.0, 3.0, 5.0 }, { 2.0, 4.0, 6.0 }, { 3.0, 5.0, 7.0 } });
            Console.WriteLine(@"Matrix B");
            Console.WriteLine(matrixB.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Multiply matrix by scalar
            // 1. Using operator "*"
            var resultM = 3.0 * matrixA;
            Console.WriteLine(@"Multiply matrix by scalar using operator *. (result = 3.0 * A)");
            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(3.0);
            Console.WriteLine(@"Multiply matrix by scalar using method Multiply. (result = A.Multiply(3.0))");
            Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

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

            // Multiply matrix by vector (right-multiply)
            var vector = new DenseVector(new[] { 1.0, 2.0, 3.0 });
            Console.WriteLine(@"Vector");
            Console.WriteLine(vector.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

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

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

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

            // Multiply vector by matrix (left-multiply)
            // 1. Using operator "*"
            resultV = vector * matrixA;
            Console.WriteLine(@"Multiply vector by matrix using operator *. (result = vec * A)");
            Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using LeftMultiply method and getting result into different vector instance
            resultV = (DenseVector)matrixA.LeftMultiply(vector);
            Console.WriteLine(@"Multiply vector by matrix using method LeftMultiply. (result = A.LeftMultiply(vec))");
            Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 3. Using LeftMultiply method and updating vector itself
            matrixA.LeftMultiply(vector, vector);
            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();
//.........这里部分代码省略.........
开发者ID:JohnnyPP,项目名称:TMP102,代码行数:101,代码来源:MatrixArithmeticOperations.cs

示例2: ColorizeVectors

        public Color[,] ColorizeVectors(Color[,] input)
        {
            if (LongestChord.firstPixel == null || LongestChord.secondPixel == null
                || LongestPerpendicularChord.firstPixel == null || LongestPerpendicularChord.secondPixel == null)
                return input;

            Color[,] output = (Color[,])input.Clone();

            double angle = LongestChord.orientation;
            double uv1CosAngle = Math.Cos(angle);
            double uv1SinAngle = Math.Sin(angle);

            double pAngle = Math.PI / 2;
            double[] rotationArray = new double[] { Math.Cos(pAngle), -1.0 * Math.Sin(pAngle), Math.Sin(pAngle), Math.Cos(pAngle) };
            Matrix<double> rotationMatrix = new DenseMatrix(2, 2, rotationArray);

            Vector<double> unitVector1 = new DenseVector(new double[] { uv1CosAngle, uv1SinAngle });
            Vector<double> unitVector2 = new DenseVector(new double[2]);
            rotationMatrix.LeftMultiply(unitVector1, unitVector2);

            double uv2CosAngle = unitVector2[0];
            double uv2SinAngle = unitVector2[1];

            int lcX = 0;
            if (uv1CosAngle > 0)
                if (LongestChord.firstPixel.X < LongestChord.secondPixel.X)
                    lcX = LongestChord.firstPixel.X;
                else
                    lcX = LongestChord.secondPixel.X;
            else
                if (LongestChord.firstPixel.X < LongestChord.secondPixel.X)
                    lcX = LongestChord.secondPixel.X;
                else
                    lcX = LongestChord.firstPixel.X;

            int lcY = 0;
            if (uv1SinAngle > 0)
                if (LongestChord.firstPixel.Y < LongestChord.secondPixel.Y)
                    lcY = LongestChord.firstPixel.Y;
                else
                    lcY = LongestChord.secondPixel.Y;
            else
                if (LongestChord.firstPixel.Y < LongestChord.secondPixel.Y)
                    lcY = LongestChord.secondPixel.Y;
                else
                    lcY = LongestChord.firstPixel.Y;

            for (int i = 0; i < LongestChord.distance; i++)
            {
                int uv1X = OffsetX + lcX + ((int)Math.Round(uv1CosAngle * i));
                int uv1Y = OffsetY + lcY + ((int)Math.Round(uv1SinAngle * i));
                output[uv1X, uv1Y] = Color.Red;
            }

            int lpcX = 0;
            if (uv2CosAngle > 0)
                if (LongestPerpendicularChord.firstPixel.X < LongestPerpendicularChord.secondPixel.X)
                    lpcX = LongestPerpendicularChord.firstPixel.X;
                else
                    lpcX = LongestPerpendicularChord.secondPixel.X;
            else
                if (LongestPerpendicularChord.firstPixel.X < LongestPerpendicularChord.secondPixel.X)
                    lpcX = LongestPerpendicularChord.secondPixel.X;
                else
                    lpcX = LongestPerpendicularChord.firstPixel.X;

            int lpcY = 0;
            if (uv2SinAngle > 0)
                if (LongestPerpendicularChord.firstPixel.Y < LongestPerpendicularChord.secondPixel.Y)
                    lpcY = LongestPerpendicularChord.firstPixel.Y;
                else
                    lpcY = LongestPerpendicularChord.secondPixel.Y;
            else
                if (LongestPerpendicularChord.firstPixel.Y < LongestPerpendicularChord.secondPixel.Y)
                    lpcY = LongestPerpendicularChord.secondPixel.Y;
                else
                    lpcY = LongestPerpendicularChord.firstPixel.Y;

            for (int i = 0; i < LongestPerpendicularChord.distance; i++)
            {
                int uv2X = OffsetX + lpcX + ((int)Math.Round(uv2CosAngle * i));
                int uv2Y = OffsetY + lpcY + ((int)Math.Round(uv2SinAngle * i));
                output[uv2X, uv2Y] = Color.Blue;
            }

            return output;
        }
开发者ID:aelex13,项目名称:RugbyIBV,代码行数:87,代码来源:ImageObject.cs


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