Exemple #1
0
        public static void Main(string[] args)
        {
            var mb = new MatrixBuilder();
            var test = mb
                .AddRow(0,0,0, 869.2285m, -389.4894m)
                .AddRow(0,0, -72298.3571m, 21209.3772m,  -389.4894m).Build();
            test.Sort();
            
            var expected = mb
                .AddRow(1, 0, 0, 0, 4.382236855892512m)
                .AddRow(0, 1, 0, 0, 0.008720130889729148m)
                .AddRow(0, 0, 1, 0, -0.16833492232696723m)
                .AddRow(0, 0, 0, 1, -0.44808630563510005m).Build();
            var testMatrix = mb
                .AddRow(12, 3123, 123, 123, 4)
                .AddRow(123, 12, 3123, 21, 4)
                .AddRow(13, 124, 4, 12, 52)
                .AddRow(123, 124, 643, 754, 94).Build();

            var solver = new Solver(testMatrix);
            var consistent = solver.Solve();
            var actual = solver.Matrix;

            Debug.WriteLine("###################");

            Console.ReadKey(true);
        }
Exemple #2
0
        public void SolveInconsistentMatrix()
        {
            var mb = new MatrixBuilder();
            var testMatrix = mb
                .AddRow(1, 2, 3)
                .AddRow(4, 5, 6)
                .AddRow(0, 0, 4).Build();

            var solver = new Solver(testMatrix);
            var consistent = solver.Solve();

            Assert.False(consistent);
        }
Exemple #3
0
        public void SolveConsistentMatrix()
        {
            var mb = new MatrixBuilder();
            var expected = mb
                .AddRow(1, 0, -1)
                .AddRow(0, 1, 2).Build();
            var testMatrix = mb
                .AddRow(1, 2, 3)
                .AddRow(4, 5, 6).Build();

            var solver = new Solver(testMatrix);
            var consistent = solver.Solve();
            var actual = solver.Matrix;

            Assert.Equal(expected, actual);
            Assert.True(consistent);
        }
Exemple #4
0
        public void SolveTwoFreeVariablesMatrix()
        {
            var mb = new MatrixBuilder();
            var expected = mb
                .AddRow(1, 0, -1, -2, -3)
                .AddRow(0, 1, 2, 3, 4)
                .AddRow(0, 0, 0, 0, 0).Build();
            var testMatrix = mb
                .AddRow(1, 2, 3, 4, 5)
                .AddRow(6, 7, 8, 9, 10)
                .AddRow(11, 12, 13, 14, 15).Build();

            var solver = new Solver(testMatrix);
            var consistent = solver.Solve();
            var actual = solver.Matrix;

            Assert.Equal(expected, actual);
            Assert.True(consistent);
        }
Exemple #5
0
        public void SolveFreeVariableMatrix()
        {
            var mb = new MatrixBuilder();
            var expected = mb
                .AddRow(1, 1, 1)
                .AddRow(0, 0, 0)
                .AddRow(0, 0, 0).Build();
            var testMatrix = mb
                .AddRow(1, 1, 1)
                .AddRow(1, 1, 1)
                .AddRow(1, 1, 1).Build();

            var solver = new Solver(testMatrix);
            var consistent = solver.Solve();
            var actual = solver.Matrix;

            Assert.Equal(expected, actual);
            Assert.True(consistent);
        }
Exemple #6
0
        public void SolveMatrixWithManyDecimals()
        {
            var mb = new MatrixBuilder();
            var expected = mb
                .AddRow(1, 0, 0, 0, 4.382236855892512m)
                .AddRow(0, 1, 0, 0, 0.008720130889729148m)
                .AddRow(0, 0, 1, 0, -0.16833492232696723m)
                .AddRow(0, 0, 0, 1, -0.44808630563510005m).Build();
            var testMatrix = mb
                .AddRow(12, 3123, 123, 123, 4)
                .AddRow(123, 12, 3123, 21, 4)
                .AddRow(13, 124, 4, 12, 52)
                .AddRow(123, 124, 643, 754, 94).Build();

            var solver = new Solver(testMatrix);
            var consistent = solver.Solve();
            var actual = solver.Matrix;

            Assert.Equal(expected, actual);
            Assert.True(consistent);
        }