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


C# UserDefinedMatrix.LU方法代码示例

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


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

示例1: CanSolveForRandomVectorWhenResultVectorGiven

        public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
        {
            var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorLU = matrixA.LU();
            var vectorb = new UserDefinedVector(Vector<Complex>.Build.Random(order, 1).ToArray());
            var vectorbCopy = vectorb.Clone();
            var resultx = new UserDefinedVector(order);
            factorLU.Solve(vectorb, resultx);

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

            var matrixBReconstruct = matrixA * resultx;

            // Check the reconstruction.
            for (var i = 0; i < vectorb.Count; 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]);
                }
            }

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

示例2: LUFailsWithNonSquareMatrix

 public void LUFailsWithNonSquareMatrix()
 {
     var matrix = new UserDefinedMatrix(3, 2);
     Assert.Throws<ArgumentException>(() => matrix.LU());
 }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:5,代码来源:UserLUTests.cs

示例3: CanInverse

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

            var matrixAInverse = factorLU.Inverse();

            // The inverse dimension is equal A
            Assert.AreEqual(matrixAInverse.RowCount, matrixAInverse.RowCount);
            Assert.AreEqual(matrixAInverse.ColumnCount, matrixAInverse.ColumnCount);

            var matrixIdentity = matrixA * matrixAInverse;

            // 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]);
                }
            }

            // Check if multiplication of A and AI produced identity matrix.
            for (var i = 0; i < matrixIdentity.RowCount; i++)
            {
                AssertHelpers.AlmostEqualRelative(matrixIdentity[i, i], Complex.One, 9);
            }
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:29,代码来源:UserLUTests.cs

示例4: CanSolveForRandomMatrixWhenResultMatrixGiven

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

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

            var matrixX = new UserDefinedMatrix(order, order);
            factorLU.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++)
                {
                    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]);
                }
            }

            // 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:rmundy,项目名称:mathnet-numerics,代码行数:47,代码来源:UserLUTests.cs

示例5: CanFactorizeRandomMatrix

        public void CanFactorizeRandomMatrix(int order)
        {
            var matrixX = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
            var factorLU = matrixX.LU();
            var matrixL = factorLU.L;
            var matrixU = factorLU.U;

            // Make sure the factors have the right dimensions.
            Assert.AreEqual(order, matrixL.RowCount);
            Assert.AreEqual(order, matrixL.ColumnCount);
            Assert.AreEqual(order, matrixU.RowCount);
            Assert.AreEqual(order, matrixU.ColumnCount);

            // Make sure the L factor is lower triangular.
            for (var i = 0; i < matrixL.RowCount; i++)
            {
                Assert.AreEqual(Complex.One, matrixL[i, i]);
                for (var j = i + 1; j < matrixL.ColumnCount; j++)
                {
                    Assert.AreEqual(Complex.Zero, matrixL[i, j]);
                }
            }

            // Make sure the U factor is upper triangular.
            for (var i = 0; i < matrixL.RowCount; i++)
            {
                for (var j = 0; j < i; j++)
                {
                    Assert.AreEqual(Complex.Zero, matrixU[i, j]);
                }
            }

            // Make sure the LU factor times it's transpose is the original matrix.
            var matrixXfromLU = matrixL * matrixU;
            var permutationInverse = factorLU.P.Inverse();
            matrixXfromLU.PermuteRows(permutationInverse);
            for (var i = 0; i < matrixXfromLU.RowCount; i++)
            {
                for (var j = 0; j < matrixXfromLU.ColumnCount; j++)
                {
                    AssertHelpers.AlmostEqualRelative(matrixX[i, j], matrixXfromLU[i, j], 9);
                }
            }
        }
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:44,代码来源:UserLUTests.cs

示例6: LUFailsWithNonSquareMatrix

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

示例7: CanSolveForRandomMatrix

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

            var matrixB = new UserDefinedMatrix(Matrix<Complex32>.Build.Random(order, order, 1).ToArray());
            var matrixX = factorLU.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++)
                {
                    Assert.AreEqual(matrixB[i, j].Real, matrixBReconstruct[i, j].Real, 1e-3f);
                    Assert.AreEqual(matrixB[i, j].Imaginary, matrixBReconstruct[i, j].Imaginary, 1e-3f);
                }
            }

            // 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:larzw,项目名称:mathnet-numerics,代码行数:36,代码来源:UserLUTests.cs

示例8: CanSolveForRandomVector

        public void CanSolveForRandomVector(int order)
        {
            var matrixA = new UserDefinedMatrix(Matrix<Complex32>.Build.Random(order, order, 1).ToArray());
            var matrixACopy = matrixA.Clone();
            var factorLU = matrixA.LU();

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

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

            var matrixBReconstruct = matrixA * resultx;

            // Check the reconstruction.
            for (var i = 0; i < order; i++)
            {
                Assert.AreEqual(vectorb[i].Real, matrixBReconstruct[i].Real, 1e-3f);
                Assert.AreEqual(vectorb[i].Imaginary, matrixBReconstruct[i].Imaginary, 1e-3f);
            }

            // 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:larzw,项目名称:mathnet-numerics,代码行数:29,代码来源:UserLUTests.cs

示例9: LUFailsWithNonSquareMatrix

 public void LUFailsWithNonSquareMatrix(int row, int col)
 {
     var I = new UserDefinedMatrix(row, col);
     I.LU();
 }
开发者ID:rafaortega,项目名称:mathnet-numerics,代码行数:5,代码来源:UserLUTests.cs


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