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


C# MatrixD.GetSubmatrix方法代码示例

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


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

示例1: TestRandomA

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

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

            LUDecompositionD d = new LUDecompositionD(a);

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

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

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

示例2: Determinant

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

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

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

示例3: TestRandomRegularA

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

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

            VectorD column2 = new VectorD(3);
            RandomHelper.Random.NextVectorD(column2, 1, 2);

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

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

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

            LUDecompositionD d = new LUDecompositionD(a);

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

            Assert.AreEqual(false, d.IsNumericallySingular);

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

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

示例4: 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 MatrixD SolveLinearEquations(MatrixD 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
              MatrixD 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,代码来源:LUDecompositionD.cs

示例5: GetSubmatrixException9

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

示例6: GetSubmatrixException8

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

示例7: GetSubmatrixException4

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

示例8: GetSubmatrixException14

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

示例9: GetSubmatrix

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

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

              Assert.AreEqual(new MatrixD(new double[,] { { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }), m.GetSubmatrix(1, 2, 0, 3));
              Assert.AreEqual(new MatrixD(new double[,] { { 8, 6, 7 }, { 12, 10, 11 } }), m.GetSubmatrix(1, 2, new int[] { 3, 1, 2}));
              Assert.AreEqual(new MatrixD(new double[,] { { 11, 12 }, { 7, 8 }, { 3, 4 } }), m.GetSubmatrix(new int[] { 2, 1, 0 }, 2, 3));
              Assert.AreEqual(new MatrixD(new double[,] { { 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,代码来源:MatrixDTest.cs


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