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


C# DenseVector.Multiply方法代码示例

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


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

示例1: Run

        /// <summary>
        /// Run example.
        /// </summary>
        /// <seealso cref="http://en.wikipedia.org/wiki/Euclidean_vector#Scalar_multiplication">Multiply vector by scalar</seealso>
        /// <seealso cref="http://en.wikipedia.org/wiki/Euclidean_vector#Dot_product">Multiply vector by vector (compute the dot product between two vectors)</seealso>
        /// <seealso cref="http://en.wikipedia.org/wiki/Euclidean_vector#Addition_and_subtraction">Vector addition and subtraction</seealso>
        /// <seealso cref="http://en.wikipedia.org/wiki/Outer_product">Outer Product of two vectors</seealso>
        public void Run()
        {
            // Initialize IFormatProvider to print matrix/vector data
            var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            formatProvider.TextInfo.ListSeparator = " ";

            // Create vector "X"
            var vectorX = new DenseVector(new[] { 1.0, 2.0, 3.0, 4.0, 5.0 });
            Console.WriteLine(@"Vector X");
            Console.WriteLine(vectorX.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Create vector "Y"
            var vectorY = new DenseVector(new[] { 5.0, 4.0, 3.0, 2.0, 1.0 });
            Console.WriteLine(@"Vector Y");
            Console.WriteLine(vectorY.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Multiply vector by scalar
            // 1. Using Multiply method and getting result into different vector instance
            var resultV = vectorX.Multiply(3.0);
            Console.WriteLine(@"Multiply vector by scalar using method Multiply. (result = X.Multiply(3.0))");
            Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using operator "*"
            resultV = 3.0 * vectorX;
            Console.WriteLine(@"Multiply vector by scalar using operator *. (result = 3.0 * X)");
            Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

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

            // Multiply vector by vector (compute the dot product between two vectors)
            // 1. Using operator "*"
            var dotProduct = vectorX * vectorY;
            Console.WriteLine(@"Dot product between two vectors using operator *. (result = X * Y)");
            Console.WriteLine(dotProduct);
            Console.WriteLine();

            // 2. Using DotProduct method and getting result into different vector instance
            dotProduct = vectorX.DotProduct(vectorY);
            Console.WriteLine(@"Dot product between two vectors using method DotProduct. (result = X.DotProduct(Y))");
            Console.WriteLine(dotProduct.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Pointwise multiplies vector with another vector
            // 1. Using PointwiseMultiply method and getting result into different vector instance
            resultV = vectorX.PointwiseMultiply(vectorY);
            Console.WriteLine(@"Pointwise multiplies vector with another vector using method PointwiseMultiply. (result = X.PointwiseMultiply(Y))");
            Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using PointwiseMultiply method and updating vector itself
            vectorX.PointwiseMultiply(vectorY, vectorX);
            Console.WriteLine(@"Pointwise multiplies vector with another vector using method PointwiseMultiply. (X.PointwiseMultiply(Y, X))");
            Console.WriteLine(vectorX.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Pointwise divide vector with another vector
            // 1. Using PointwiseDivide method and getting result into different vector instance
            resultV = vectorX.PointwiseDivide(vectorY);
            Console.WriteLine(@"Pointwise divide vector with another vector using method PointwiseDivide. (result = X.PointwiseDivide(Y))");
            Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using PointwiseDivide method and updating vector itself
            vectorX.PointwiseDivide(vectorY, vectorX);
            Console.WriteLine(@"Pointwise divide vector with another vector using method PointwiseDivide. (X.PointwiseDivide(Y, X))");
            Console.WriteLine(vectorX.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // Addition
            // 1. Using operator "+"
            resultV = vectorX + vectorY;
            Console.WriteLine(@"Add vectors using operator +. (result = X + Y)");
            Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 2. Using Add method and getting result into different vector instance
            resultV = vectorX.Add(vectorY);
            Console.WriteLine(@"Add vectors using method Add. (result = X.Add(Y))");
            Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
            Console.WriteLine();

            // 3. Using Add method and updating vector itself
            vectorX.Add(vectorY, vectorX);
            Console.WriteLine(@"Add vectors using method Add. (X.Add(Y, X))");
            Console.WriteLine(vectorX.ToString("#0.00\t", formatProvider));
//.........这里部分代码省略.........
开发者ID:Mistrall,项目名称:Solvation,代码行数:101,代码来源:VectorArithmeticOperations.cs

示例2: SetRealVertices

        private static void SetRealVertices(Workspace workspace)
        {
            Vector<double> fittedPlaneVector = GeometryHelper.FitPlaneToPoints(workspace.PointCloud.ToArray());

            if (fittedPlaneVector == null)
            {
                return;
            }

            Point3D projectedPoint = GeometryHelper.ProjectPoint3DToPlane(workspace.PointCloud.First(), fittedPlaneVector);

            Vector<double> planeNormal = new DenseVector(new[] { fittedPlaneVector[0], fittedPlaneVector[1], fittedPlaneVector[2] });

            Point3D[] vertices3D = workspace.Vertices3D;

            Point[] vertices = workspace.Vertices.ToArray();

            for (int i = 0; i < vertices.Length; i++)
            {

                Vector<double> pointOnPlane = new DenseVector(new[] { projectedPoint.X, projectedPoint.Y, projectedPoint.Z });
                Vector<double> pointOnLine = new DenseVector(new double[] { vertices3D[i].X, vertices3D[i].Y, vertices3D[i].Z });

                double d = (pointOnPlane.Subtract(pointOnLine)).DotProduct(planeNormal) / (pointOnLine.DotProduct(planeNormal));

                Vector<double> intersection = pointOnLine + pointOnLine.Multiply(d);

                workspace.FittedVertices[i] = new Point3D(intersection[0], intersection[1], intersection[2]);
            }

            workspace.PlaneVector = fittedPlaneVector;
        }
开发者ID:frksptr,项目名称:kinect-demo,代码行数:32,代码来源:WorkspaceProcessor.cs

示例3: SetRealVertices

        public void SetRealVertices(Workspace workspace)
        {
            Vector<double> fittedPlaneVector = GeometryHelper.FitPlaneToPoints(workspace.PointCloud.ToArray());

            if (fittedPlaneVector == null)
            {
                return;
            }

            Point3D projectedPoint = GeometryHelper.ProjectPoint3DToPlane(workspace.PointCloud.First(), fittedPlaneVector);

            Vector<double> planeNormal = new DenseVector(new[] { fittedPlaneVector[0], fittedPlaneVector[1], fittedPlaneVector[2] });

            CameraSpacePoint[] csps = { new CameraSpacePoint() };

            Point[] vertices = workspace.Vertices.ToArray();

            for (int i = 0; i < vertices.Length; i++)
            {
                Point vertex = vertices[i];

                kinectStreamer.CoordinateMapper.MapDepthPointsToCameraSpace(
                    new[] {
                        new DepthSpacePoint {
                            X = (float)vertex.X,
                            Y = (float)vertex.Y
                        }
                    },
                    new ushort[] { 1 }, csps);

                Vector<double> pointOnPlane = new DenseVector(new[] { projectedPoint.X, projectedPoint.Y, projectedPoint.Z });
                Vector<double> pointOnLine = new DenseVector(new double[] { csps[0].X, csps[0].Y, csps[0].Z });

                double d = (pointOnPlane.Subtract(pointOnLine)).DotProduct(planeNormal) / (pointOnLine.DotProduct(planeNormal));

                Vector<double> intersection = pointOnLine + pointOnLine.Multiply(d);

                workspace.FittedVertices[i] = new Point3D(intersection[0], intersection[1], intersection[2]);
            }

            workspace.PlaneVector = fittedPlaneVector;
        }
开发者ID:kovand11,项目名称:kinect-demo,代码行数:42,代码来源:CloudView.cs

示例4: InitializeVertices

        /// <summary>
        /// Construct an initial simplex, given starting guesses for the constants, and
        /// initial step sizes for each dimension
        /// </summary>
        private static Vector<double>[] InitializeVertices(SimplexConstant[] simplexConstants)
        {
            int numDimensions = simplexConstants.Length;
            Vector<double>[] vertices = new Vector<double>[numDimensions + 1];

            // define one point of the simplex as the given initial guesses
            Vector<double> p0 = new DenseVector(numDimensions);
            for (int i = 0; i < numDimensions; i++)
            {
                p0[i] = simplexConstants[i].Value;
            }

            // now fill in the vertices, creating the additional points as:
            // P(i) = P(0) + Scale(i) * UnitVector(i)
            vertices[0] = p0;
            for (int i = 0; i < numDimensions; i++)
            {
                double scale = simplexConstants[i].InitialPerturbation;
                Vector unitVector = new DenseVector(numDimensions);
                unitVector[i] = 1;
                vertices[i + 1] = p0.Add(unitVector.Multiply(scale));
            }
            return vertices;
        }
开发者ID:AlexandreBurel,项目名称:pwiz-mzdb,代码行数:28,代码来源:NelderMeadSimplex.cs

示例5: ComputeCentroid

 /// <summary>
 /// Compute the centroid of all points except the worst
 /// </summary>
 /// <param name="vertices"></param>
 /// <param name="errorProfile"></param>
 /// <returns></returns>
 private static Vector ComputeCentroid(Vector<double>[] vertices, ErrorProfile errorProfile)
 {
     int numVertices = vertices.Length;
     // find the centroid of all points except the worst one
     Vector centroid = new DenseVector(numVertices - 1);
     for (int i = 0; i < numVertices; i++)
     {
         if (i != errorProfile.HighestIndex)
         {
             centroid = (Vector) centroid.Add(vertices[i]);
         }
     }
     return (Vector) centroid.Multiply(1.0d / (numVertices - 1));
 }
开发者ID:AlexandreBurel,项目名称:pwiz-mzdb,代码行数:20,代码来源:NelderMeadSimplex.cs

示例6: ProjectPoint3DToPlane

        public static Point3D ProjectPoint3DToPlane(Point3D point, Vector<double> planeVectors)
        {
            double distance = CalculatePointPlaneDistance(point, planeVectors);

            double a = planeVectors[0];
            double b = planeVectors[1];
            double c = planeVectors[2];

            Vector<double> planeNormal = new DenseVector(new[] { a, b, c });

            double x = point.X;
            double y = point.Y;
            double z = point.Z;

            Vector<double> pointVector = new DenseVector(new[] { x, y, z });

            pointVector.Subtract(planeNormal.Multiply(distance));

            return new Point3D
            {
                X = pointVector[0],
                Y = pointVector[1],
                Z = pointVector[2]
            };
        }
开发者ID:kovand11,项目名称:kinect-demo,代码行数:25,代码来源:GeometryHelper.cs

示例7: bar3gfBarnes

        public static double[] bar3gfBarnes(double[][] ec,double[] ep, double[] ed, double ten)
        {
            // Compute the internal force vector for a cable element according to:
            // FORM-FINDING  AND  ANALYSIS  OF  PRESTRESSED NETS  AND  MEMBRANES
            // by M. R. BARNES (1988)
            //ed = [a_1 a_2 ... a_6]; Element nodal displacements
            //ep = [E A]; element properties
            //ten = [ten]; Specified initial element tension

            //OUTPUT:
            //ef = F_int = [f_1 f_2 ... f_6]';
            //ec format: [x,y,z][node1,node2...]
            //ed format: [node1x, node1y, node1z, node2x...]

            double l0 = getElementLength(ec);
            double[][] ecUpdated = updateEcWithDisp(ec, ed);
            double l = getElementLength(ecUpdated); //Current length

            //Current element force
            double tm = ten + (ep[0] * ep[1] / l0) * (l - l0);

            //Direction vector
            Vector v = new DenseVector(3);

            for (int i = 0; i < 3; i++)
            {
                v[i] = ecUpdated[i][0] - ecUpdated[i][1];
            }

            double vl = v.Norm(2);
            Vector x = new DenseVector(6);

            for (int i = 0; i < 3; i++)
            {
                x[i] = v[i] / vl;
            }

            //Reverse direction vector
            for (int i = 0; i < 3; i++)
            {
                x[i+3] = -v[i] / vl;
            }

            return x.Multiply(tm).ToArray();
        }
开发者ID:CALFEM,项目名称:calfem-csharp,代码行数:45,代码来源:Calfem.cs


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