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


C# MatrixValue.GetComplexMatrix方法代码示例

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


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

示例1: CholeskyDecomposition

        /// <summary>
        /// Cholesky algorithm for symmetric and positive definite matrix.
        /// </summary>
        /// <param name="Arg">Square, symmetric matrix.</param>
        /// <returns>Structure to access L and isspd flag.</returns>
        public CholeskyDecomposition(MatrixValue Arg)
        {
            // Initialize.
            var A = Arg.GetComplexMatrix();
            n = Arg.DimensionY;
            L = new ScalarValue[n][];

            for (int i = 0; i < n; i++)
                L[i] = new ScalarValue[n];

            isspd = Arg.DimensionX == n;

            // Main loop.
            for (int i = 0; i < n; i++)
            {
                var Lrowi = L[i];
                var d = ScalarValue.Zero;

                for (int j = 0; j < i; j++)
                {
                    var Lrowj = L[j];
                    var s = new ScalarValue();

                    for (int k = 0; k < j; k++)
                        s += Lrowi[k] * Lrowj[k].Conjugate();

                    s = (A[i][j] - s) / L[j][j];
                    Lrowi[j] = s;
                    d += s * s.Conjugate();
                    isspd = isspd && (A[j][i] == A[i][j]);
                }

                d = A[i][i] - d;
                isspd = isspd & (d.Abs() > 0.0);
                L[i][i] = d.Sqrt();

                for (int k = i + 1; k < n; k++)
                    L[i][k] = ScalarValue.Zero;
            }
        }
开发者ID:FlorianRappl,项目名称:YAMP,代码行数:45,代码来源:CholeskyDecomposition.cs

示例2: Solve

        /// <summary>Solve A*X = B</summary>
        /// <param name="B">  A Matrix with as many rows as A and any number of columns.
        /// </param>
        /// <returns>     X so that L*L'*X = B
        /// </returns>
        public override MatrixValue Solve(MatrixValue B)
        {
            if (B.DimensionY != n)
                throw new YAMPDifferentDimensionsException(n, 1, B.DimensionY, 1);

            if (!isspd)
                throw new YAMPMatrixFormatException(SpecialMatrixFormat.SymmetricPositiveDefinite.ToString());

            // Copy right hand side.
            var X = B.GetComplexMatrix();
            int nx = B.DimensionX;

            // Solve L*Y = B;
            for (var k = 0; k < n; k++)
            {
                for (var i = k + 1; i < n; i++)
                {
                    for (var j = 0; j < nx; j++)
                    {
                        X[i][j] -= X[k][j] * L[i][k];
                    }
                }

                for (var j = 0; j < nx; j++)
                {
                    X[k][j] /= L[k][k];
                }
            }

            // Solve L'*X = Y;
            for (var k = n - 1; k >= 0; k--)
            {
                for (var j = 0; j < nx; j++)
                {
                    X[k][j] /= L[k][k];
                }

                for (var i = 0; i < k; i++)
                {
                    for (var j = 0; j < nx; j++)
                    {
                        X[i][j] -= X[k][j] * L[k][i];
                    }
                }
            }

            return new MatrixValue(X, n, nx);
        }
开发者ID:FlorianRappl,项目名称:YAMP,代码行数:53,代码来源:CholeskyDecomposition.cs


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