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


C# Vector.L2Norm方法代码示例

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


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

示例1: Constraint

 public Constraint(double x, double y)
 {
     _vector = Vector<double>.Build.DenseOfArray(new[] { x, y });
     X = x;
     Y = y;
     Length = _vector.L2Norm();
     UnitVector = _vector.Divide(Length);
 }
开发者ID:LeelaLinux,项目名称:LineProjection,代码行数:8,代码来源:Constraint.cs

示例2: Solve

        /// <summary>
        /// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
        /// solution vector and x is the unknown vector.
        /// </summary>
        /// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
        /// <param name="input">The solution vector, <c>b</c></param>
        /// <param name="result">The result vector, <c>x</c></param>
        public void Solve(Matrix matrix, Vector input, Vector result)
        {
            // If we were stopped before, we are no longer
            // We're doing this at the start of the method to ensure
            // that we can use these fields immediately.
            _hasBeenStopped = false;

            // Error checks
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix");
            }

            if (matrix.RowCount != matrix.ColumnCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixSquare, "matrix");
            }

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (result.Count != input.Count)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            if (input.Count != matrix.RowCount)
            {
                throw Matrix.DimensionsDontMatch<ArgumentException>(input, matrix);
            }

            // Initialize the solver fields
            // Set the convergence monitor
            if (_iterator == null)
            {
                _iterator = Iterator.CreateDefault();
            }

            if (_preconditioner == null)
            {
                _preconditioner = new UnitPreconditioner();
            }

            _preconditioner.Initialize(matrix);

            var d = new DenseVector(input.Count);
            var r = DenseVector.OfVector(input);

            var uodd = new DenseVector(input.Count);
            var ueven = new DenseVector(input.Count);

            var v = new DenseVector(input.Count);
            var pseudoResiduals = DenseVector.OfVector(input);

            var x = new DenseVector(input.Count);
            var yodd = new DenseVector(input.Count);
            var yeven = DenseVector.OfVector(input);

            // Temp vectors
            var temp = new DenseVector(input.Count);
            var temp1 = new DenseVector(input.Count);
            var temp2 = new DenseVector(input.Count);

            // Define the scalars
            Complex32 alpha = 0;
            Complex32 eta = 0;
            float theta = 0;

            // Initialize
            var tau = input.L2Norm().Real;
            Complex32 rho = tau*tau;

            // Calculate the initial values for v
            // M temp = yEven
            _preconditioner.Approximate(yeven, temp);

            // v = A temp
            matrix.Multiply(temp, v);

            // Set uOdd
            v.CopyTo(ueven);

            // Start the iteration
            var iterationNumber = 0;
            while (ShouldContinue(iterationNumber, result, input, pseudoResiduals))
            {
//.........这里部分代码省略.........
开发者ID:koponk,项目名称:mathnet-numerics,代码行数:101,代码来源:TFQMR.cs

示例3: FindCVect

        public static Vector<double> FindCVect(Vector<double> aVect, Vector<double> bVect, double alpha, double beta, double C)
        {
            aVect /= aVect.L2Norm();
            bVect /= bVect.L2Norm();
            alpha *= Math.PI / 180.0;
            beta *= Math.PI / 180.0;

            Vector<double> planeNormal = Calculator.CrossProduct(aVect, bVect);
            planeNormal /= planeNormal.L2Norm();
            double theta = Math.Acos(planeNormal[2]);
            double phi = Math.Atan2(planeNormal[1], planeNormal[0]);

            Matrix<double> Rz = DenseMatrix.OfArray(new double[,] { { Math.Cos(phi), Math.Sin(phi), 0},
                                                                    {-Math.Sin(phi), Math.Cos(phi), 0},
                                                                    {     0,             0,         1} });
            Matrix<double> Ry = DenseMatrix.OfArray(new double[,] { { Math.Cos(theta), 0, -Math.Sin(theta)},
                                                                    {     0,           1,       0         },
                                                                     {Math.Sin(theta), 0,  Math.Cos(theta)} });

            aVect = Ry * Rz * aVect;
            bVect = Ry * Rz * bVect;

            double cx1 = (Math.Cos(beta) * bVect[1] - Math.Cos(alpha) * aVect[1]);
            double cx2 = (aVect[0] * bVect[1] - bVect[0] * aVect[1]);

            double cx = cx1 / cx2;
            double cy = (Math.Cos(beta) * bVect[0] - Math.Cos(alpha) * aVect[0]) / (aVect[1] * bVect[0] - bVect[1] * aVect[0]);

            Vector<double> cVect = DenseVector.OfArray(new double[] { cx, cy, Math.Sqrt(1 - cx * cx - cy * cy) });
            cVect = C * Rz.Inverse() * Ry.Inverse() * cVect;

            return cVect;
        }
开发者ID:hakgagik,项目名称:CRYLAB,代码行数:33,代码来源:SuperCell.cs


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