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


C# Matrix.SubMatrix方法代码示例

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


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

示例1: TestMethodMatrix

 public void TestMethodMatrix()
 {
     Matrix matrix1 = new Matrix(2, 3);
     Assert.AreEqual(matrix1.Row, 2);
     Assert.AreEqual(matrix1.Column, 3);
     Matrix matrix2 = new Matrix(new double[,] { { 1, 2, 0 }, { 3, 4, 5 } });
     Assert.AreEqual(matrix2.Row, 2);
     Assert.AreEqual(matrix2.Column, 3);
     matrix2.Resize(2, 2);
     Matrix matrix3 = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
     Assert.AreEqual(matrix2.GetHashCode(), matrix3.GetHashCode());
     Assert.IsTrue(matrix2.Equals(matrix3));
     matrix3.AddRowToRow(0, 1, -1);
     Assert.AreEqual(matrix3, new Matrix(new double[,] { { 1, 2 }, { 2, 2 } }));
     matrix3.AddRowToRow(1, 0, 1);
     Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 2, 2 } }));
     matrix3.MultiplyFactorToRow(1, 0.5);
     Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 } }));
     matrix3.AddNewRowToEnd(new Vector(new double[] { 5, 6 }));
     Assert.AreEqual(matrix3[2, 0], 5);
     Assert.AreEqual(matrix3[2, 1], 6);
     Matrix matrix4 = matrix3.SubMatrix(1, 1, 2, 1);
     Assert.AreEqual(matrix4, new Matrix(new double[,] { { 1 }, { 6 } }));
     Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 }, { 5, 6 } }));
     matrix3.DelRowFromEnd();
     Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 } }));
     Matrix matrix5 = new Matrix(new double[,] { { 1, 2 }, { 1, 2 } });
     Assert.AreEqual(matrix3 + matrix5, new Matrix(new double[,] { { 4, 6 }, { 2, 3 } }));
     Assert.AreEqual(matrix3 - matrix5, new Matrix(new double[,] { { 2, 2 }, { 0, -1 } }));
     Assert.AreEqual(matrix3 * matrix5, new Matrix(new double[,] { { 7, 14 }, { 2, 4 } }));
     Assert.AreEqual(matrix5 * matrix3, new Matrix(new double[,] { { 5, 6 }, { 5, 6 } }));
     Assert.AreEqual(matrix3 * matrix4, new Matrix(new double[,] { { 27 }, { 7 } }));
 }
开发者ID:kidfruit,项目名称:matrixdotnet,代码行数:33,代码来源:TestBasic.cs

示例2: ComputeShift

 /// <summary>
 /// The shift is generally taken to be the smallest eigenvalue of the 2 × 2 matrix in the bottom.
 /// </summary>
 /// <returns></returns>
 private Complex ComputeShift(Matrix mat)
 {
     try {
         Matrix subMat = mat.SubMatrix(mat.Height - 2, mat.Height, mat.Width - 2, mat.Width);
         Complex trace = subMat.Trace();
         Complex det = subMat.Determinant();
         Complex eig1 = (trace + ComplexMath.Sqrt(trace * trace - 4 * det)) / 2;
         Complex eig2 = (trace - ComplexMath.Sqrt(trace * trace - 4 * det)) / 2;
         Complex eigen = ComplexMath.Min(eig1, eig2);
         return eigen;
     } catch (MatrixException) {
         return 0;
     }
 }
开发者ID:DonDoff,项目名称:Maths,代码行数:18,代码来源:SVD.cs

示例3: Divide8

 private static IEnumerable<Tuple<Matrix, Matrix>> Divide8(Matrix a, Matrix b)
 {
     yield return
         Tuple.Create(a.SubMatrix(0, 0, a.Height/2, a.Width/2), b.SubMatrix(0, 0, b.Height/2, b.Width/2));
     yield return
         Tuple.Create(a.SubMatrix(0, a.Width/2, a.Height/2, a.Width/2 + a.Width%2),
             b.SubMatrix(b.Height/2, 0, b.Height/2 + b.Height%2, b.Width/2));
     yield return
         Tuple.Create(a.SubMatrix(0, 0, a.Height/2, a.Width/2),
             b.SubMatrix(0, b.Width/2, b.Height/2, b.Width/2 + b.Width%2));
     yield return Tuple.Create(a.SubMatrix(0, a.Width/2, a.Height/2, a.Width/2 + a.Width%2),
         b.SubMatrix(b.Height/2, b.Width/2, b.Height/2 + b.Height%2, b.Width/2 + b.Width%2));
     yield return
         Tuple.Create(a.SubMatrix(a.Height/2, 0, a.Height/2 + a.Height%2, a.Width/2),
             b.SubMatrix(0, 0, b.Height/2, b.Width/2));
     yield return Tuple.Create(a.SubMatrix(a.Height/2, a.Width/2, a.Height/2 + a.Height%2,
         a.Width/2 + a.Width%2), b.SubMatrix(b.Height/2, 0, b.Height/2 + b.Height%2, b.Width/2));
     yield return
         Tuple.Create(a.SubMatrix(a.Height/2, 0, a.Height/2 + a.Height%2, a.Width/2),
             b.SubMatrix(0, b.Width/2, b.Height/2, b.Width/2 + b.Width%2));
     yield return Tuple.Create(a.SubMatrix(a.Height/2, a.Width/2, a.Height/2 + a.Height%2,
         a.Width/2 + a.Width%2), b.SubMatrix(b.Height/2, b.Width/2, b.Height/2 + b.Height%2,
             b.Width/2 + b.Width%2));
 }
开发者ID:AndriyKhavro,项目名称:Parcs.NET,代码行数:24,代码来源:MatrixesModule.cs

示例4: InvertByRowOperations

        public Matrix InvertByRowOperations()
        {
            if (!IsSquare)
                throw new Exception("Matrix not square!");

            Matrix retval = new Matrix(Rows, Columns * 2);

            // build the inversion matrix
            for (int i = 0; i < Columns; i++)
                for (int j = 0; j < Rows; j++)
                    retval[j, i] = this[j, i];

            for (int i = Columns; i < Columns * 2; i++)
                for (int j = 0; j < Rows; j++)
                    retval[j, i] = ((i - Columns) == j) ? 1 : 0;

            // do the columns one by one
            for (int col = 0; col < Columns; col++)
            {
                if (retval[col, col] == new Complex(0, 0))
                {
                    for (int row = col + 1; row < Rows; row++)
                    {
                        if (retval[row, col] != new Complex(0, 0))
                        {
                            retval.AddRow(col, row, 1);
                        }
                    }
                }

                if (retval[col, col] == new Complex(0, 0))
                {
                    // apparently we are singular.
                    throw new Exception("Singular matrix.");
                }

                retval.ScaleRow(col, 1 / retval[col, col]);

                for (int row = 0; row < Rows; row++)
                {
                    if (row == col)
                        continue;

                    Complex scale = -retval[row, col];

                    retval.AddRow(row, col, scale);
                }
            }

            // extract the actual inversion matrix
            return retval.SubMatrix(0, Columns, Rows, Columns);
        }
开发者ID:eylvisaker,项目名称:tbsuite,代码行数:52,代码来源:Matrix.cs

示例5: TestMatrixSubtraction

        public void TestMatrixSubtraction()
        {
            Matrix m1, m2;
            m1 = new Matrix(2, 2);
            m2 = new Matrix(2, 2);

            // init m1
            m1.SetValue(0, 0, 1);
            m1.SetValue(0, 1, 1);
            m1.SetValue(1, 0, 1);
            m1.SetValue(1, 1, 1);

            // init m2
            m2.SetValue(0, 0, 2);
            m2.SetValue(0, 1, 2);
            m2.SetValue(1, 0, 2);
            m2.SetValue(1, 1, 2);

            Matrix diff = m1.SubMatrix(m2);
            Matrix result;

            result = new Matrix(2, 2);
            result.SetValue(0, 0, -1);
            result.SetValue(0, 1, -1);
            result.SetValue(1, 0, -1);
            result.SetValue(1, 1, -1);

            Assert.AreEqual(result, diff);

            // test minus operator
            diff = m1 - m2;
            Assert.AreEqual(result, diff);
        }
开发者ID:AlexEyler,项目名称:MathLib,代码行数:33,代码来源:UnitTestMatrix.cs

示例6: TransformDx2y2

        private static OrbitalDesignation TransformDx2y2(Matrix sym)
        {
            if (sym.SubMatrix(0, 0, 2, 2).IsDiagonal)
                return OrbitalDesignation.dx2y2;

            return OrbitalDesignation.none;
        }
开发者ID:eylvisaker,项目名称:tbsuite,代码行数:7,代码来源:OrbitalDesignation.cs


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