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


C# MatrixValue.GetRealMatrix方法代码示例

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


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

示例1: Eigenvalues

        /// <summary>
        /// Check for symmetry, then construct the eigenvalue decomposition
        /// </summary>
        /// <param name="Arg">Square matrix</param>
        /// <returns>Structure to access D and V.</returns>
        public Eigenvalues(MatrixValue Arg)
        {
            var A = Arg.GetRealMatrix();
            n = Arg.DimensionX;
            V = new double[n][];

            for (int i = 0; i < n; i++)
                V[i] = new double[n];

            d = new double[n];
            e = new double[n];

            issymmetric = true;

            for (int j = 0; (j < n) && issymmetric; j++)
            {
                for (int i = 0; (i < n) && issymmetric; i++)
                    issymmetric = (A[i][j] == A[j][i]);
            }

            if (issymmetric)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                        V[i][j] = A[i][j];
                }

                // Tridiagonalize.
                tred2();

                // Diagonalize.
                tql2();
            }
            else
            {
                H = new double[n][];

                for (int i2 = 0; i2 < n; i2++)
                    H[i2] = new double[n];

                ort = new double[n];

                for (int j = 0; j < n; j++)
                {
                    for (int i = 0; i < n; i++)
                        H[i][j] = A[i][j];
                }

                // Reduce to Hessenberg form.
                orthes();

                // Reduce Hessenberg to real Schur form.
                hqr2();
            }
        }
开发者ID:FlorianRappl,项目名称:YAMP,代码行数:61,代码来源:Eigenvalues.cs

示例2: SingularValueDecomposition

        /// <summary>
        /// Construct the singular value decomposition
        /// </summary>
        /// <param name="Arg">Rectangular matrix</param>
        /// <returns>Structure to access U, S and V.</returns>
        public SingularValueDecomposition(MatrixValue Arg)
        {
            // Derived from LINPACK code.
            // Initialize.
            var A = Arg.GetRealMatrix();
            m = Arg.DimensionY;
            n = Arg.DimensionX;
            var nu = Math.Min(m, n);
            s = new double[Math.Min(m + 1, n)];
            U = new double[m][];

            for (int i = 0; i < m; i++)
                U[i] = new double[nu];

            V = new double[n][];

            for (int i2 = 0; i2 < n; i2++)
                V[i2] = new double[n];

            var e = new double[n];
            var work = new double[m];
            var wantu = true;
            var wantv = true;

            // Reduce A to bidiagonal form, storing the diagonal elements
            // in s and the super-diagonal elements in e.

            int nct = Math.Min(m - 1, n);
            int nrt = Math.Max(0, Math.Min(n - 2, m));

            for (int k = 0; k < Math.Max(nct, nrt); k++)
            {
                if (k < nct)
                {
                    // Compute the transformation for the k-th column and
                    // place the k-th diagonal in s[k].
                    // Compute 2-norm of k-th column without under/overflow.
                    s[k] = 0;

                    for (int i = k; i < m; i++)
                        s[k] = Helpers.Hypot(s[k], A[i][k]);

                    if (s[k] != 0.0)
                    {
                        if (A[k][k] < 0.0)
                            s[k] = -s[k];

                        for (int i = k; i < m; i++)
                            A[i][k] /= s[k];

                        A[k][k] += 1.0;
                    }

                    s[k] = -s[k];
                }

                for (int j = k + 1; j < n; j++)
                {
                    if ((k < nct) & (s[k] != 0.0))
                    {
                        // Apply the transformation.
                        double t = 0;

                        for (int i = k; i < m; i++)
                            t += A[i][k] * A[i][j];

                        t = (-t) / A[k][k];

                        for (int i = k; i < m; i++)
                            A[i][j] += t * A[i][k];
                    }

                    // Place the k-th row of A into e for the
                    // subsequent calculation of the row transformation.
                    e[j] = A[k][j];
                }

                if (wantu & (k < nct))
                {
                    // Place the transformation in U for subsequent back
                    // multiplication.
                    for (int i = k; i < m; i++)
                        U[i][k] = A[i][k];
                }

                if (k < nrt)
                {
                    // Compute the k-th row transformation and place the
                    // k-th super-diagonal in e[k].
                    // Compute 2-norm without under/overflow.
                    e[k] = 0;

                    for (int i = k + 1; i < n; i++)
                        e[k] = Helpers.Hypot(e[k], e[i]);

//.........这里部分代码省略.........
开发者ID:FlorianRappl,项目名称:YAMP,代码行数:101,代码来源:SingularValueDecomposition.cs


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