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


C# UserDefinedMatrix.QR方法代码示例

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


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

示例1: CanSolveForRandomVectorWhenResultVectorGivenUsingThinQR

        public void CanSolveForRandomVectorWhenResultVectorGivenUsingThinQR(int order)
        {
            var matrixA = new UserDefinedMatrix(Matrix<double>.Build.Random(order, order, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorQR = matrixA.QR(QRMethod.Thin);
            var vectorb = new UserDefinedVector(Vector<double>.Build.Random(order, 1).ToArray());
            var vectorbCopy = vectorb.Clone();
            var resultx = new UserDefinedVector(order);
            factorQR.Solve(vectorb, resultx);

            Assert.AreEqual(vectorb.Count, resultx.Count);

            var matrixBReconstruct = matrixA * resultx;

            // Check the reconstruction.
            for (var i = 0; i < vectorb.Count; i++)
            {
                Assert.AreEqual(vectorb[i], matrixBReconstruct[i], 1.0e-11);
            }

            // Make sure A didn't change.
            for (var i = 0; i < matrixA.RowCount; i++)
            {
                for (var j = 0; j < matrixA.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
                }
            }

            // Make sure b didn't change.
            for (var i = 0; i < vectorb.Count; i++)
            {
                Assert.AreEqual(vectorbCopy[i], vectorb[i]);
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:35,代码来源:UserQRTests.cs

示例2: CanSolveForRandomMatrixWhenResultMatrixGivenUsingThinQR

        public void CanSolveForRandomMatrixWhenResultMatrixGivenUsingThinQR(int order)
        {
            var matrixA = new UserDefinedMatrix(Matrix<double>.Build.Random(order, order, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorQR = matrixA.QR(QRMethod.Thin);

            var matrixB = new UserDefinedMatrix(Matrix<double>.Build.Random(order, order, 1).ToArray());
            var matrixBCopy = matrixB.Clone();

            var matrixX = new UserDefinedMatrix(order, order);
            factorQR.Solve(matrixB, matrixX);

            // The solution X row dimension is equal to the column dimension of A
            Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

            // The solution X has the same number of columns as B
            Assert.AreEqual(matrixB.ColumnCount, matrixX.ColumnCount);

            var matrixBReconstruct = matrixA * matrixX;

            // Check the reconstruction.
            for (var i = 0; i < matrixB.RowCount; i++)
            {
                for (var j = 0; j < matrixB.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixB[i, j], matrixBReconstruct[i, j], 1.0e-11);
                }
            }

            // Make sure A didn't change.
            for (var i = 0; i < matrixA.RowCount; i++)
            {
                for (var j = 0; j < matrixA.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
                }
            }

            // Make sure B didn't change.
            for (var i = 0; i < matrixB.RowCount; i++)
            {
                for (var j = 0; j < matrixB.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixBCopy[i, j], matrixB[i, j]);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:47,代码来源:UserQRTests.cs

示例3: CanFactorizeRandomMatrixUsingThinQR

        public void CanFactorizeRandomMatrixUsingThinQR(int row, int column)
        {
            var matrixA = new UserDefinedMatrix(Matrix<double>.Build.Random(row, column, 1).ToArray());
            var factorQR = matrixA.QR(QRMethod.Thin);
            var q = factorQR.Q;
            var r = factorQR.R;

            // Make sure the R has the right dimensions.
            Assert.AreEqual(column, r.RowCount);
            Assert.AreEqual(column, r.ColumnCount);

            // Make sure the Q has the right dimensions.
            Assert.AreEqual(row, q.RowCount);
            Assert.AreEqual(column, q.ColumnCount);

            // Make sure the R factor is upper triangular.
            for (var i = 0; i < r.RowCount; i++)
            {
                for (var j = 0; j < r.ColumnCount; j++)
                {
                    if (i > j)
                    {
                        Assert.AreEqual(0.0, r[i, j]);
                    }
                }
            }

            // Make sure the Q*R is the original matrix.
            var matrixQfromR = q * r;
            for (var i = 0; i < matrixQfromR.RowCount; i++)
            {
                for (var j = 0; j < matrixQfromR.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixA[i, j], matrixQfromR[i, j], 1.0e-11);
                }
            }
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:37,代码来源:UserQRTests.cs

示例4: CanSolveForRandomVectorUsingThinQR

        public void CanSolveForRandomVectorUsingThinQR(int order)
        {
            var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorQR = matrixA.QR(QRMethod.Thin);

            var vectorb = new UserDefinedVector(Vector<Complex>.Build.Random(order, 1).ToArray());
            var resultx = factorQR.Solve(vectorb);

            Assert.AreEqual(matrixA.ColumnCount, resultx.Count);

            var matrixBReconstruct = matrixA * resultx;

            // Check the reconstruction.
            for (var i = 0; i < order; i++)
            {
                AssertHelpers.AlmostEqual(vectorb[i], matrixBReconstruct[i], 10);
            }

            // Make sure A didn't change.
            for (var i = 0; i < matrixA.RowCount; i++)
            {
                for (var j = 0; j < matrixA.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
                }
            }
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:28,代码来源:UserQRTests.cs

示例5: CanSolveForRandomMatrix

        public void CanSolveForRandomMatrix(int order)
        {
            var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorQR = matrixA.QR();

            var matrixB = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
            var matrixX = factorQR.Solve(matrixB);

            // The solution X row dimension is equal to the column dimension of A
            Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);

            // The solution X has the same number of columns as B
            Assert.AreEqual(matrixB.ColumnCount, matrixX.ColumnCount);

            var matrixBReconstruct = matrixA * matrixX;

            // Check the reconstruction.
            for (var i = 0; i < matrixB.RowCount; i++)
            {
                for (var j = 0; j < matrixB.ColumnCount; j++)
                {
                    AssertHelpers.AlmostEqual(matrixB[i, j], matrixBReconstruct[i, j], 10);
                }
            }

            // Make sure A didn't change.
            for (var i = 0; i < matrixA.RowCount; i++)
            {
                for (var j = 0; j < matrixA.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
                }
            }
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:35,代码来源:UserQRTests.cs

示例6: CanFactorizeRandomMatrix

        public void CanFactorizeRandomMatrix(int row, int column)
        {
            var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(row, column, 1).ToArray());
            var factorQR = matrixA.QR(QRMethod.Full);
            var q = factorQR.Q;
            var r = factorQR.R;

            // Make sure the R has the right dimensions.
            Assert.AreEqual(row, r.RowCount);
            Assert.AreEqual(column, r.ColumnCount);

            // Make sure the Q has the right dimensions.
            Assert.AreEqual(row, q.RowCount);
            Assert.AreEqual(row, q.ColumnCount);

            // Make sure the R factor is upper triangular.
            for (var i = 0; i < r.RowCount; i++)
            {
                for (var j = 0; j < r.ColumnCount; j++)
                {
                    if (i > j)
                    {
                        Assert.AreEqual(Complex.Zero, r[i, j]);
                    }
                }
            }

            // Make sure the Q*R is the original matrix.
            var matrixQfromR = q * r;
            for (var i = 0; i < matrixQfromR.RowCount; i++)
            {
                for (var j = 0; j < matrixQfromR.ColumnCount; j++)
                {
                    AssertHelpers.AlmostEqualRelative(matrixA[i, j], matrixQfromR[i, j], 9);
                }
            }
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:37,代码来源:UserQRTests.cs

示例7: CanFactorizeRandomMatrix

        public void CanFactorizeRandomMatrix(int row, int column)
        {
            var matrixA = new UserDefinedMatrix(Matrix<Complex32>.Build.Random(row, column, 1).ToArray());
            var factorQR = matrixA.QR(QRMethod.Full);
            var q = factorQR.Q;
            var r = factorQR.R;

            // Make sure the R has the right dimensions.
            Assert.AreEqual(row, r.RowCount);
            Assert.AreEqual(column, r.ColumnCount);

            // Make sure the Q has the right dimensions.
            Assert.AreEqual(row, q.RowCount);
            Assert.AreEqual(row, q.ColumnCount);

            // Make sure the R factor is upper triangular.
            for (var i = 0; i < r.RowCount; i++)
            {
                for (var j = 0; j < r.ColumnCount; j++)
                {
                    if (i > j)
                    {
                        Assert.AreEqual(Complex32.Zero, r[i, j]);
                    }
                }
            }

            // Make sure the Q*R is the original matrix.
            var matrixQfromR = q * r;
            for (var i = 0; i < matrixQfromR.RowCount; i++)
            {
                for (var j = 0; j < matrixQfromR.ColumnCount; j++)
                {
                    Assert.AreEqual(matrixA[i, j].Real, matrixQfromR[i, j].Real, 1e-3f);
                    Assert.AreEqual(matrixA[i, j].Imaginary, matrixQfromR[i, j].Imaginary, 1e-3f);
                }
            }

            // Make sure the Q is unitary --> (Q*)x(Q) = I
            var matrixQсtQ = q.ConjugateTranspose() * q;
            for (var i = 0; i < matrixQсtQ.RowCount; i++)
            {
                for (var j = 0; j < matrixQсtQ.ColumnCount; j++)
                {
                    if (i == j)
                    {
                        Assert.AreEqual(matrixQсtQ[i, j].Real, 1.0f, 1e-3f);
                        Assert.AreEqual(matrixQсtQ[i, j].Imaginary, 0.0f, 1e-3f);
                    }
                    else
                    {
                        Assert.AreEqual(matrixQсtQ[i, j].Real, 0.0f, 1e-3f);
                        Assert.AreEqual(matrixQсtQ[i, j].Imaginary, 0.0f, 1e-3f);
                    }
                }
            }
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:57,代码来源:UserQRTests.cs


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