コード例 #1
0
        public void TestCreateRowEchelonForm()
        {
            Matrix mat = new Matrix()
            {
                { 1, 1, 2, 0 },
                { 0, 1, -1, 0 },
                { 3, 4, 5, 0 },
                { 3, 5, 4, 0 }
            };

            LinearSystem ls = new LinearSystem(mat);

            ls.CreateLowerTriangularCoefficientMatrix();

            Assert.AreEqual(ls.CoefficientMatrix,
                            new Matrix
            {
                { 1, 1, 2, 0 },
                { 0, 1, -1, 0 },
                { 0, 0, 0, 0 },
                { 0, 0, 0, 0 }
            });


            mat = new Matrix()
            {
                { 1, 1, -1, 2 },
                { -2, 0, 1, -2 },
                { 5, -1, 2, 4 },
                { 2, 6, -3, 5 }
            };

            ls = new LinearSystem(mat);
            ls.CreateLowerTriangularCoefficientMatrix();

            Assert.AreEqual(ls.CoefficientMatrix,
                            new Matrix
            {
                { 1, 1, -1, 2 },
                { 0, 1, -0.5, 1 },
                { 0, 0, 1, 0 },
                { 0, 0, 0, -3 }
            });
        }
コード例 #2
0
        public void TestBothTriangularCoefficientMatrix()
        {
            Matrix mat = new Matrix()
            {
                { 1, 1, -1, 2 },
                { -2, 0, 1, -2 },
                { 5, -1, 2, 4 },
                { 2, 6, -3, 5 }
            };

            LinearSystem ls = new LinearSystem(mat);

            ls.CreateLowerTriangularCoefficientMatrix();
            ls.CreateUpperTriangularCoefficientMatrix();

            Assert.AreEqual(ls.CoefficientMatrix,
                            new Matrix
            {
                { 1, 0, 0, 1 },
                { 0, 1, 0, 1 },
                { 0, 0, 1, 0 },
                { 0, 0, 0, -3 }
            });

            mat = new Matrix()
            {
                { 1, 1, -1, 2 },
                { -2, 0, 1, -2 },
                { 5, -1, 2, 4 },
                { 2, 6, -3, 5 }
            };

            ls = new LinearSystem(mat);
            ls.CreateUpperTriangularCoefficientMatrix();
            ls.CreateLowerTriangularCoefficientMatrix();

            Assert.AreEqual(ls.CoefficientMatrix,
                            new Matrix
            {
                { 1, 0, 0, 1 },
                { 0, 1, 0, 1 },
                { 0, 0, 1, 0 },
                { 0, 0, 0, -3 }
            });

            mat = new Matrix()
            {
                { 2, 3, 4 },
                { 3, 2, 2 },
            };

            ls = new LinearSystem(mat);
            ls.CreateLowerTriangularCoefficientMatrix();
            ls.CreateUpperTriangularCoefficientMatrix();

            Assert.IsTrue(ls.CoefficientMatrix.Equals(
                              new Matrix
            {
                { 1, 0, -0.4 },
                { 0, 1, 1.6 },
            }));

            mat = new Matrix()
            {
                { 6, 7, 5 },
                { 1, 1, 0 },
            };

            ls = new LinearSystem(mat);
            ls.CreateLowerTriangularCoefficientMatrix();
            ls.CreateUpperTriangularCoefficientMatrix();

            Assert.IsTrue(ls.CoefficientMatrix.Equals(
                              new Matrix
            {
                { 1, 0, -5 },
                { 0, 1, 5 },
            }));

            mat = new Matrix()
            {
                { 2, -3, 9 },
                { 0, 1, 2 },
            };

            ls = new LinearSystem(mat);
            ls.CreateLowerTriangularCoefficientMatrix();
            ls.CreateUpperTriangularCoefficientMatrix();

            Assert.IsTrue(ls.CoefficientMatrix.Equals(
                              new Matrix
            {
                { 1, 0, 7.5 },
                { 0, 1, 2 },
            }));
        }