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


C# Complex32.DenseMatrix类代码示例

本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Complex32.DenseMatrix的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix类的具体用法?C# DenseMatrix怎么用?C# DenseMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DenseMatrix类属于MathNet.Numerics.LinearAlgebra.Complex32命名空间,在下文中一共展示了DenseMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanCheckRankOfSquareSingular

        public void CanCheckRankOfSquareSingular(int order)
        {
            var matrixA = new DenseMatrix(order, order);
            matrixA[0, 0] = 1;
            matrixA[order - 1, order - 1] = 1;
            for (var i = 1; i < order - 1; i++)
            {
                matrixA[i, i - 1] = 1;
                matrixA[i, i + 1] = 1;
                matrixA[i - 1, i] = 1;
                matrixA[i + 1, i] = 1;
            }

            var factorSvd = matrixA.Svd();

            Assert.AreEqual(factorSvd.Determinant, Complex32.Zero);
            Assert.AreEqual(factorSvd.Rank, order - 1);
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:18,代码来源:SvdTests.cs

示例2: CanCheckRankOfSquareSingular

        public void CanCheckRankOfSquareSingular([Values(10, 50, 100)] int order)
        {
            var A = new DenseMatrix(order, order);
            A[0, 0] = 1;
            A[order - 1, order - 1] = 1;
            for (var i = 1; i < order - 1; i++)
            {
                A[i, i - 1] = 1;
                A[i, i + 1] = 1;
                A[i - 1, i] = 1;
                A[i + 1, i] = 1;
            }

            var factorEvd = A.Evd();

            Assert.AreEqual(factorEvd.Determinant, Complex32.Zero);
            Assert.AreEqual(factorEvd.Rank, order - 1);
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:18,代码来源:EvdTests.cs

示例3: CanAddSparseMatricesBothWays

        public void CanAddSparseMatricesBothWays()
        {
            var m1 = new SparseMatrix(1, 3);
            var m2 = SparseMatrix.OfArray(new Complex32[,] { { 0, 1, 1 } });
            var sum1 = m1 + m2;
            var sum2 = m2 + m1;
            Assert.IsTrue(sum1.Equals(m2));
            Assert.IsTrue(sum1.Equals(sum2));

            var sparseResult = new SparseMatrix(1, 3);
            sparseResult.Add(m2, sparseResult);
            Assert.IsTrue(sparseResult.Equals(sum1));

            sparseResult = SparseMatrix.OfArray(new Complex32[,] { { 0, 1, 1 } });
            sparseResult.Add(m1, sparseResult);
            Assert.IsTrue(sparseResult.Equals(sum1));

            sparseResult = SparseMatrix.OfArray(new Complex32[,] { { 0, 1, 1 } });
            m1.Add(sparseResult, sparseResult);
            Assert.IsTrue(sparseResult.Equals(sum1));

            sparseResult = SparseMatrix.OfArray(new Complex32[,] { { 0, 1, 1 } });
            sparseResult.Add(sparseResult, sparseResult);
            Assert.IsTrue(sparseResult.Equals(2*sum1));

            var denseResult = new DenseMatrix(1, 3);
            denseResult.Add(m2, denseResult);
            Assert.IsTrue(denseResult.Equals(sum1));

            denseResult = DenseMatrix.OfArray(new Complex32[,] {{0, 1, 1}});
            denseResult.Add(m1, denseResult);
            Assert.IsTrue(denseResult.Equals(sum1));

            var m3 = DenseMatrix.OfArray(new Complex32[,] {{0, 1, 1}});
            var sum3 = m1 + m3;
            var sum4 = m3 + m1;
            Assert.IsTrue(sum3.Equals(m3));
            Assert.IsTrue(sum3.Equals(sum4));
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:39,代码来源:SparseMatrixTests.cs

示例4: Identity

        /// <summary>
        /// Initializes a square <see cref="DenseMatrix"/> with all zero's except for ones on the diagonal.
        /// </summary>
        /// <param name="order">the size of the square matrix.</param>
        /// <returns>A dense identity matrix.</returns>
        /// <exception cref="ArgumentException">
        /// If <paramref name="order"/> is less than one.
        /// </exception>
        public static DenseMatrix Identity(int order)
        {
            var m = new DenseMatrix(order);
            for (var i = 0; i < order; i++)
            {
                m.Data[(i * order) + i] = 1.0f;
            }

            return m;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:18,代码来源:DenseMatrix.cs

示例5: OfDiagonalVector

 /// <summary>
 /// Create a new dense matrix with the diagonal as a copy of the given vector.
 /// This new matrix will be independent from the vector.
 /// A new memory block will be allocated for storing the matrix.
 /// </summary>
 public static DenseMatrix OfDiagonalVector(int rows, int columns, Vector<Complex32> diagonal)
 {
     var m = new DenseMatrix(rows, columns);
     m.SetDiagonal(diagonal);
     return m;
 }
开发者ID:kapilash,项目名称:mathnet-numerics,代码行数:11,代码来源:DenseMatrix.cs

示例6: OfDiagonalArray

 /// <summary>
 /// Create a new dense matrix with the diagonal as a copy of the given array.
 /// This new matrix will be independent from the array.
 /// A new memory block will be allocated for storing the matrix.
 /// </summary>
 public static DenseMatrix OfDiagonalArray(int rows, int columns, Complex32[] diagonal)
 {
     var m = new DenseMatrix(rows, columns);
     m.SetDiagonal(diagonal);
     return m;
 }
开发者ID:kapilash,项目名称:mathnet-numerics,代码行数:11,代码来源:DenseMatrix.cs

示例7: LUFailsWithNonSquareMatrix

 public void LUFailsWithNonSquareMatrix()
 {
     var matrix = new DenseMatrix(3, 1);
     Assert.That(() => matrix.LU(), Throws.ArgumentException);
 }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:5,代码来源:LUTests.cs

示例8: Add

        /// <summary>
        /// Adds another matrix to this matrix.
        /// </summary>
        /// <param name="other">The matrix to add to this matrix.</param>
        /// <returns>The result of the addition.</returns>
        /// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
        public override Matrix<Complex32> Add(Matrix<Complex32> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other.RowCount != RowCount || other.ColumnCount != ColumnCount)
            {
                throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions);
            }

            Matrix<Complex32> result;
            if (other is DiagonalMatrix)
            {
                result = new DiagonalMatrix(RowCount, ColumnCount);
            }
            else
            {
                result = new DenseMatrix(RowCount, ColumnCount);
            }

            Add(other, result);
            return result;
        }
开发者ID:jiangzhen3s,项目名称:mathnet-numerics,代码行数:32,代码来源:DiagonalMatrix.cs

示例9: Subtract

        /// <summary>
        /// Subtracts another matrix from this matrix.
        /// </summary>
        /// <param name="other">The matrix to subtract.</param>
        /// <returns>The result of the subtraction.</returns>
        /// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
        public override Matrix<Complex32> Subtract(Matrix<Complex32> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other.RowCount != RowCount || other.ColumnCount != ColumnCount)
            {
                throw DimensionsDontMatch<ArgumentOutOfRangeException>(this, other, "other");
            }

            Matrix<Complex32> result;
            if (other is DiagonalMatrix)
            {
                result = new DiagonalMatrix(RowCount, ColumnCount);
            }
            else
            {
                result = new DenseMatrix(RowCount, ColumnCount);
            }

            Subtract(other, result);
            return result;
        }
开发者ID:bstrausser,项目名称:mathnet-numerics,代码行数:32,代码来源:DiagonalMatrix.cs

示例10: CanComputeThinQRFactorTallMatrixWithWorkArray

        public void CanComputeThinQRFactorTallMatrixWithWorkArray()
        {
            var matrix = _matrices["Tall3x2"];
            var r = new Complex32[matrix.ColumnCount*matrix.ColumnCount];
            var tau = new Complex32[3];
            var q = new Complex32[matrix.RowCount*matrix.ColumnCount];
            Array.Copy(matrix.Values, q, q.Length);

            var work = new Complex32[matrix.ColumnCount*Control.BlockSize];
            Control.LinearAlgebraProvider.ThinQRFactor(q, matrix.RowCount, matrix.ColumnCount, r, tau, work);

            var mq = new DenseMatrix(matrix.RowCount, matrix.ColumnCount, q);
            var mr = new DenseMatrix(matrix.ColumnCount, matrix.ColumnCount, r);
            var a = mq*mr;
            for (var row = 0; row < matrix.RowCount; row++)
            {
                for (var col = 0; col < matrix.ColumnCount; col++)
                {
                    AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 5);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:22,代码来源:LinearAlgebraProviderTests.cs

示例11: CanComputeQRFactorWideMatrix

        public void CanComputeQRFactorWideMatrix()
        {
            var matrix = _matrices["Wide2x3"];
            var r = new Complex32[matrix.RowCount*matrix.ColumnCount];
            Array.Copy(matrix.Values, r, r.Length);

            var tau = new Complex32[3];
            var q = new Complex32[matrix.RowCount*matrix.RowCount];
            Control.LinearAlgebraProvider.QRFactor(r, matrix.RowCount, matrix.ColumnCount, q, tau);

            var mr = new DenseMatrix(matrix.RowCount, matrix.ColumnCount, r).UpperTriangle();
            var mq = new DenseMatrix(matrix.RowCount, matrix.RowCount, q);
            var a = mq*mr;

            for (var row = 0; row < matrix.RowCount; row++)
            {
                for (var col = 0; col < matrix.ColumnCount; col++)
                {
                    AssertHelpers.AlmostEqualRelative(matrix[row, col], a[row, col], 5);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:22,代码来源:LinearAlgebraProviderTests.cs

示例12: CanSolveUsingCholesky

        public void CanSolveUsingCholesky()
        {
            var matrix = new DenseMatrix(3, 3, new Complex32[] {1, 1, 1, 1, 2, 3, 1, 3, 6});
            var a = new Complex32[] {1, 1, 1, 1, 2, 3, 1, 3, 6};

            var b = new[] {new Complex32(1.0f, 0.0f), 2.0f, 3.0f, 4.0f, 5.0f, 6.0f};
            Control.LinearAlgebraProvider.CholeskySolve(a, 3, b, 2);

            AssertHelpers.AlmostEqualRelative(b[0], 0, 5);
            AssertHelpers.AlmostEqualRelative(b[1], 1, 5);
            AssertHelpers.AlmostEqualRelative(b[2], 0, 5);
            AssertHelpers.AlmostEqualRelative(b[3], 3, 5);
            AssertHelpers.AlmostEqualRelative(b[4], 1, 5);
            AssertHelpers.AlmostEqualRelative(b[5], 0, 5);

            NotModified(3, 3, a, matrix);
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:17,代码来源:LinearAlgebraProviderTests.cs

示例13: CanMultiplyTallAndWideMatricesWithUpdate

        public void CanMultiplyTallAndWideMatricesWithUpdate()
        {
            var x = _matrices["Tall3x2"];
            var y = _matrices["Wide2x3"];
            var c = new DenseMatrix(x.RowCount, y.ColumnCount);

            Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 2.2f, x.Values, x.RowCount, x.ColumnCount, y.Values, y.RowCount, y.ColumnCount, 1.0f, c.Values);

            for (var i = 0; i < c.RowCount; i++)
            {
                for (var j = 0; j < c.ColumnCount; j++)
                {
                    var test = 2.2f*x.Row(i)*y.Column(j);

                    // if they are both close to zero, skip
                    if (Math.Abs(test.Real) < 1e-7 && Math.Abs(c[i, j].Real) < 1e-7)
                    {
                        continue;
                    }

                    AssertHelpers.AlmostEqualRelative(2.2f*x.Row(i)*y.Column(j), c[i, j], 5);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:24,代码来源:LinearAlgebraProviderTests.cs

示例14: CanMultiplyWideAndTallMatricesWithUpdate

        public void CanMultiplyWideAndTallMatricesWithUpdate()
        {
            var x = _matrices["Wide2x3"];
            var y = _matrices["Tall3x2"];
            var c = new DenseMatrix(x.RowCount, y.ColumnCount);

            Control.LinearAlgebraProvider.MatrixMultiplyWithUpdate(Transpose.DontTranspose, Transpose.DontTranspose, 2.2f, x.Values, x.RowCount, x.ColumnCount, y.Values, y.RowCount, y.ColumnCount, 1.0f, c.Values);

            for (var i = 0; i < c.RowCount; i++)
            {
                for (var j = 0; j < c.ColumnCount; j++)
                {
                    AssertHelpers.AlmostEqualRelative(2.2f*x.Row(i)*y.Column(j), c[i, j], 5);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:16,代码来源:LinearAlgebraProviderTests.cs

示例15: CanMultiplyTallAndWideMatrices

        public void CanMultiplyTallAndWideMatrices()
        {
            var x = _matrices["Tall3x2"];
            var y = _matrices["Wide2x3"];
            var c = new DenseMatrix(x.RowCount, y.ColumnCount);

            Control.LinearAlgebraProvider.MatrixMultiply(x.Values, x.RowCount, x.ColumnCount, y.Values, y.RowCount, y.ColumnCount, c.Values);

            for (var i = 0; i < c.RowCount; i++)
            {
                for (var j = 0; j < c.ColumnCount; j++)
                {
                    AssertHelpers.AlmostEqualRelative(x.Row(i)*y.Column(j), c[i, j], 5);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:16,代码来源:LinearAlgebraProviderTests.cs


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