Beispiel #1
0
 [Fact] public void Matrix() =>
 Test(@"\begin{bmatrix}11 & 12 \\ 21 & 22 \\ 31 & 32\end{bmatrix}", MathS.Matrix(new Entity[, ]
 {
     { 11, 12 },
     { 21, 22 },
     { 31, 32 }
 }));
Beispiel #2
0
 [Fact] public void MatrixDivision2()
 => Assert.Equal(
     MathS.Matrix(new Entity[, ] {
     { "1 / 2", "1 / 2" },
     { "1 / 2", "-1 / 2" }
 }).InnerSimplified,
     MathS.I_2 / H);
Beispiel #3
0
        public void TestSystem2()
        {
            var res = ("x", "y").SolveSystem("x", "y");
            var exp = MathS.Matrix(new Entity[, ] {
                { 0, 0 }
            });

            Assert.Equal(exp, res);
        }
Beispiel #4
0
        [Fact] public void ZeroRectMatrix()
        {
            var m = MathS.Matrix(new Entity[, ] {
                { 0, 0, 0 },
                { 0, 0, 0 }
            });

            Assert.Equal(m, MathS.ZeroMatrix(2, 3));
        }
Beispiel #5
0
        public void TestSystem8()
        {
            var res = ("x", "y", "z", "t", "k", "p", "r", "l").SolveSystem("x", "y", "z", "t", "k", "p", "r", "l");
            var exp = MathS.Matrix(new Entity[, ] {
                { 0, 0, 0, 0, 0, 0, 0, 0 }
            });

            Assert.Equal(exp, res);
        }
Beispiel #6
0
 public void Identity2()
 {
     Assert.Equal(
         MathS.Matrix(new Entity[, ]
     {
         { 1, 0 },
         { 0, 1 }
     }),
         MathS.IdentityMatrix(2));
 }
Beispiel #7
0
        public void TransposeDoubleOperationMatrix()
        {
            var a = MathS.Matrix(new Entity[, ]
            {
                { 1, 2 },
                { 3, 4 }
            });

            Assert.Equal(a, a.T.T);
        }
Beispiel #8
0
 public void Identity2x3()
 {
     Assert.Equal(
         MathS.Matrix(new Entity[, ]
     {
         { 1, 0, 0 },
         { 0, 1, 0 },
     }),
         MathS.IdentityMatrix(2, 3));
 }
Beispiel #9
0
        [Fact] public void UnsuccessfulMatrixDivisionInnerSimplified()
        {
            var singularMatrix = MathS.Matrix(new Entity[, ]
            {
                { 1, 2 },
                { 2, 4 }
            });

            Assert.Equal(MathS.I_2 / (Entity)singularMatrix, (MathS.I_2 / (Entity)singularMatrix).InnerSimplified);
        }
Beispiel #10
0
        [Fact] public void GaussianElimination()
        {
            var m = MathS.Matrix(new Entity[, ] {
                { 32, 41, 1 },
                { 3, 4, 1 },
                { 3, 1, 4 }
            });
            var g = m.RowEchelonForm;

            Assert.Equal(m.Determinant, (g.MainDiagonal[0] * g.MainDiagonal[1] * g.MainDiagonal[2]).InnerSimplified);
        }
Beispiel #11
0
        public void TransposeImmutability()
        {
            var a  = MathS.Vector(1, 2);
            var aT = MathS.Matrix(new Entity[, ] {
                { 1, 2 }
            });

            Assert.Equal(aT, a.T);
            var origin = MathS.Vector(1, 2);

            Assert.Equal(origin, a);
        }
Beispiel #12
0
        [Fact] public void WithElementMatrix2()
        {
            var jordan = MathS.I_3.WithElement(0, 1, 5).WithElement(1, 2, 8);

            Assert.Equal(
                MathS.Matrix(new Entity[, ]
            {
                { 1, 5, 0 },
                { 0, 1, 8 },
                { 0, 0, 1 }
            }),
                jordan);
        }
Beispiel #13
0
        [Fact] public void Adjugate1()
        {
            var H = MathS.Matrix(new Entity[, ]
            {
                { "1", "2", "6" },
                { "3", "2", "9" },
                { "1", "1", "9" },
            });
            var actual = H.Adjugate is { } adj&& H.Determinant is { } det ? (adj / det).Evaled : null;
            var expected = H.Inverse;

            Assert.Equal(expected, actual);
        }
Beispiel #14
0
        [Fact] public void Adjugate1()
        {
            var H = MathS.Matrix(new Entity[, ]
            {
                { "1", "2", "6" },
                { "3", "2", "9" },
                { "1", "1", "9" },
            });
            var actual   = (H.Adjugate / H.Determinant).Evaled;
            var expected = H.ComputeInverse();

            Assert.Equal(expected, actual);
        }
Beispiel #15
0
        [Fact] public void WithColumnMatrix1()
        {
            var m = MathS.I_4.WithColumn(2, MathS.Vector(1, 2, 3, 4));

            Assert.Equal(
                MathS.Matrix(new Entity[, ]
            {
                { 1, 0, 1, 0 },
                { 0, 1, 2, 0 },
                { 0, 0, 3, 0 },
                { 0, 0, 4, 1 }
            }),
                m);
        }
Beispiel #16
0
        [Fact] public void WithRowMatrix1()
        {
            var m = MathS.I_4.WithRow(2, MathS.Vector(1, 2, 3, 4).T);

            Assert.Equal(
                MathS.Matrix(new Entity[, ]
            {
                { 1, 0, 0, 0 },
                { 0, 1, 0, 0 },
                { 1, 2, 3, 4 },
                { 0, 0, 0, 1 }
            }),
                m);
        }
Beispiel #17
0
        public void Determ()
        {
            var A = MathS.Matrix(new Entity[, ]
            {
                { "A", "B" },
                { "C", "D" }
            });
            var v = A.Determinant.Substitute("A", 1)
                    .Substitute("B", 2)
                    .Substitute("C", 3)
                    .Substitute("D", 4);

            Assert.Equal(-2, v.EvalNumerical());
        }
Beispiel #18
0
        public void TransposeDoubleOperationMatrixImmutability()
        {
            var a = MathS.Matrix(new Entity[, ]
            {
                { 1, 2 },
                { 3, 4 }
            });
            var b = MathS.Matrix(new Entity[, ]
            {
                { 1, 2 },
                { 3, 4 }
            });
            var c = a.T;

            Assert.Equal(b, c.T);
        }
Beispiel #19
0
        [Fact] public void WithColumnMatrix2()
        {
            var m = MathS.IdentityMatrix(5)
                    .WithColumn(2, MathS.Vector(1, 2, 3, 4, 5))
                    .WithColumn(4, MathS.Vector(1, 3, 5, 9, 1))
                    .WithColumn(4, MathS.Vector(5, 6, 7, 8, 9));

            Assert.Equal(
                MathS.Matrix(new Entity[, ]
            {
                { 1, 0, 1, 0, 5 },
                { 0, 1, 2, 0, 6 },
                { 0, 0, 3, 0, 7 },
                { 0, 0, 4, 1, 8 },
                { 0, 0, 5, 0, 9 }
            }),
                m);
        }
Beispiel #20
0
        [Fact] public void WithRowMatrix2()
        {
            var m = MathS.IdentityMatrix(5)
                    .WithRow(2, MathS.Vector(1, 2, 3, 4, 5).T)
                    .WithRow(4, MathS.Vector(1, 3, 5, 9, 1).T)
                    .WithRow(4, MathS.Vector(5, 6, 7, 8, 9).T);

            Assert.Equal(
                MathS.Matrix(new Entity[, ]
            {
                { 1, 0, 0, 0, 0 },
                { 0, 1, 0, 0, 0 },
                { 1, 2, 3, 4, 5 },
                { 0, 0, 0, 1, 0 },
                { 5, 6, 7, 8, 9 }
            }),
                m);
        }
Beispiel #21
0
        public void TransposeMatrix()
        {
            var a = MathS.Matrix(new Entity[, ]
            {
                { 1, 2 },
                { 3, 4 }
            });

            Assert.Equal(1, a[0, 0]);
            Assert.Equal(2, a[0, 1]);
            Assert.Equal(3, a[1, 0]);
            Assert.Equal(4, a[1, 1]);

            Assert.Equal(1, a.T[0, 0]);
            Assert.Equal(3, a.T[0, 1]);
            Assert.Equal(2, a.T[1, 0]);
            Assert.Equal(4, a.T[1, 1]);
        }
Beispiel #22
0
        [Fact] public void MatrixDivision3x3()
        => Assert.Equal(
            MathS.Matrix(new Entity[, ] {
            { 1, -3 },
            { 3, -8 }
        }),

            MathS.Matrix(new Entity[, ] {
            { 1, 0 },
            { 3, 1 }
        })
            /
            MathS.Matrix(new Entity[, ] {
            { 1, 3 },
            { 0, 1 }
        })

            );