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


C# MatrixF.GetSubmatrix方法代码示例

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


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

示例1: TestRandomA

        public void TestRandomA()
        {
            RandomHelper.Random = new Random(1);

              for (int i = 0; i < 100; i++)
              {
            // Create A.
            MatrixF a = new MatrixF(3, 3);
            RandomHelper.Random.NextMatrixF(a, 0, 1);

            LUDecompositionF d = new LUDecompositionF(a);

            if (d.IsNumericallySingular == false)
            {
              // Check solving of linear equations.
              MatrixF b = new MatrixF(3, 2);
              RandomHelper.Random.NextMatrixF(b, 0, 1);

              MatrixF x = d.SolveLinearEquations(b);
              MatrixF b2 = a * x;
              Assert.IsTrue(MatrixF.AreNumericallyEqual(b, b2, 0.01f));

              MatrixF aPermuted = d.L * d.U;
              Assert.IsTrue(MatrixF.AreNumericallyEqual(aPermuted, a.GetSubmatrix(d.PivotPermutationVector, 0, 2)));
            }
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:27,代码来源:LUDecompositionFTest.cs

示例2: Determinant

        public void Determinant()
        {
            MatrixF a = new MatrixF(new float[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 0, 1, 2, 0 }, { 1, 0, 1, 0 } });

              LUDecompositionF d = new LUDecompositionF(a);
              Assert.AreEqual(false, d.IsNumericallySingular);
              Assert.IsTrue(Numeric.AreEqual(-24, d.Determinant));

              MatrixF aPermuted = d.L * d.U;
              Assert.IsTrue(MatrixF.AreNumericallyEqual(aPermuted, a.GetSubmatrix(d.PivotPermutationVector, 0, 3)));
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:11,代码来源:LUDecompositionFTest.cs

示例3: GetSubmatrixException9

 public void GetSubmatrixException9()
 {
     MatrixF m = new MatrixF(4, 3, rowMajor, MatrixOrder.RowMajor);
       m.GetSubmatrix(0, 4, new int[]{1});
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:5,代码来源:MatrixFTest.cs

示例4: GetSubmatrixException8

 public void GetSubmatrixException8()
 {
     MatrixF m = new MatrixF(4, 3, rowMajor, MatrixOrder.RowMajor);
       m.GetSubmatrix(0, 1, 0, -1);
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:5,代码来源:MatrixFTest.cs

示例5: GetSubmatrixException4

 public void GetSubmatrixException4()
 {
     MatrixF m = new MatrixF(4, 3, rowMajor, MatrixOrder.RowMajor);
       m.GetSubmatrix(new int[] { 1 }, 1, 0);
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:5,代码来源:MatrixFTest.cs

示例6: GetSubmatrixException14

 public void GetSubmatrixException14()
 {
     MatrixF m = new MatrixF(4, 3, rowMajor, MatrixOrder.RowMajor);
       m.GetSubmatrix(new int[] { 2 }, new int[] { 4 });
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:5,代码来源:MatrixFTest.cs

示例7: GetSubmatrix

        public void GetSubmatrix()
        {
            MatrixF m = new MatrixF(3, 4, rowMajor, MatrixOrder.RowMajor);

              Assert.AreEqual(m, m.GetSubmatrix(0, 2, 0, 3));
              Assert.AreEqual(new MatrixF(1, 1, 1), m.GetSubmatrix(0, 0, 0, 0));
              Assert.AreEqual(new MatrixF(1, 1, 12), m.GetSubmatrix(2, 2, 3, 3));
              Assert.AreEqual(new MatrixF(1, 1, 12), m.GetSubmatrix(2, 2, new int[] { 3 }));
              Assert.AreEqual(new MatrixF(1, 1, 4), m.GetSubmatrix(new int[] {0}, 3, 3));
              Assert.AreEqual(new MatrixF(1, 1, 10), m.GetSubmatrix(new int[] { 2 }, new int[] { 1 }));

              Assert.AreEqual(new MatrixF(new float[,] { { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }), m.GetSubmatrix(1, 2, 0, 3));
              Assert.AreEqual(new MatrixF(new float[,] { { 8, 6, 7 }, { 12, 10, 11 } }), m.GetSubmatrix(1, 2, new int[] { 3, 1, 2}));
              Assert.AreEqual(new MatrixF(new float[,] { { 11, 12 }, { 7, 8 }, { 3, 4 } }), m.GetSubmatrix(new int[] { 2, 1, 0 }, 2, 3));
              Assert.AreEqual(new MatrixF(new float[,] { { 8, 7, 5, 6 }, { 12, 11, 9, 10 }, { 4, 3, 1, 2 } }), m.GetSubmatrix(new int[] { 1, 2, 0 }, new int[] {3, 2, 0, 1}));

              Assert.AreEqual(null, m.GetSubmatrix(null, 0, 2));
              Assert.AreEqual(null, m.GetSubmatrix(0, 2, null));
              Assert.AreEqual(null, m.GetSubmatrix(null, new int[] { 1 }));
              Assert.AreEqual(null, m.GetSubmatrix(new int[] { 1 }, null));
              Assert.AreEqual(null, m.GetSubmatrix(null, null));
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:22,代码来源:MatrixFTest.cs

示例8: TestRandomRegularA

        public void TestRandomRegularA()
        {
            RandomHelper.Random = new Random(1);

              for (int i = 0; i < 100; i++)
              {
            VectorF column1 = new VectorF(3);
            RandomHelper.Random.NextVectorF(column1, 1, 2);

            VectorF column2 = new VectorF(3);
            RandomHelper.Random.NextVectorF(column2, 1, 2);

            // Make linearly independent.
            if (column1 / column1[0] == column2 / column2[0])
              column2[0]++;

            // Create linearly independent third column.
            VectorF column3 = column1 + column2;
            column3[1]++;

            // Create A.
            MatrixF a = new MatrixF(3, 3);
            a.SetColumn(0, column1);
            a.SetColumn(1, column2);
            a.SetColumn(2, column3);

            LUDecompositionF d = new LUDecompositionF(a);

            MatrixF aPermuted = d.L * d.U;
            Assert.IsTrue(MatrixF.AreNumericallyEqual(aPermuted, a.GetSubmatrix(d.PivotPermutationVector, 0, 2)));
            aPermuted = d.L * d.U; // Repeat with to test cached values.
            Assert.IsTrue(MatrixF.AreNumericallyEqual(aPermuted, a.GetSubmatrix(d.PivotPermutationVector, 0, 2)));

            Assert.AreEqual(false, d.IsNumericallySingular);

            // Check solving of linear equations.
            MatrixF b = new MatrixF(3, 2);
            RandomHelper.Random.NextMatrixF(b, 0, 1);

            MatrixF x = d.SolveLinearEquations(b);
            MatrixF b2 = a * x;
            Assert.IsTrue(MatrixF.AreNumericallyEqual(b, b2, 0.01f));
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:44,代码来源:LUDecompositionFTest.cs

示例9: SolveLinearEquations

        //--------------------------------------------------------------
        /// <summary>
        /// Solves the equation <c>A * X = B</c>.
        /// </summary>
        /// <param name="matrixB">The matrix B with as many rows as A and any number of columns.</param>
        /// <returns>X, so that <c>A * X = B</c>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="matrixB"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The number of rows does not match.
        /// </exception>
        /// <exception cref="MathematicsException">
        /// The matrix A is numerically singular.
        /// </exception>
        public MatrixF SolveLinearEquations(MatrixF matrixB)
        {
            if (matrixB == null)
            throw new ArgumentNullException("matrixB");
              if (matrixB.NumberOfRows != _m)
            throw new ArgumentException("The number of rows does not match.", "matrixB");
              if (IsNumericallySingular)
            throw new MathematicsException("The original matrix A is numerically singular.");

              // Copy right hand side with pivoting
              MatrixF x = matrixB.GetSubmatrix(_pivotVector, 0, matrixB.NumberOfColumns-1);

              // Solve L*Y = B(piv,:)
              for (int k = 0; k < _n; k++)
            for (int i = k + 1; i < _n; i++)
              for (int j = 0; j < matrixB.NumberOfColumns; j++)
            x[i, j] -= x[k, j] * _lu[i, k];

              // Solve U*X = Y;
              for (int k = _n - 1; k >= 0; k--)
              {
            for (int j = 0; j < matrixB.NumberOfColumns; j++)
              x[k, j] /= _lu[k, k];
            for (int i = 0; i < k; i++)
              for (int j = 0; j < matrixB.NumberOfColumns; j++)
            x[i, j] -= x[k, j] * _lu[i, k];
              }
              return x;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:44,代码来源:LUDecompositionF.cs


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