[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 } }));
[Fact] public void MatrixDivision2() => Assert.Equal( MathS.Matrix(new Entity[, ] { { "1 / 2", "1 / 2" }, { "1 / 2", "-1 / 2" } }).InnerSimplified, MathS.I_2 / H);
public void TestSystem2() { var res = ("x", "y").SolveSystem("x", "y"); var exp = MathS.Matrix(new Entity[, ] { { 0, 0 } }); Assert.Equal(exp, res); }
[Fact] public void ZeroRectMatrix() { var m = MathS.Matrix(new Entity[, ] { { 0, 0, 0 }, { 0, 0, 0 } }); Assert.Equal(m, MathS.ZeroMatrix(2, 3)); }
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); }
public void Identity2() { Assert.Equal( MathS.Matrix(new Entity[, ] { { 1, 0 }, { 0, 1 } }), MathS.IdentityMatrix(2)); }
public void TransposeDoubleOperationMatrix() { var a = MathS.Matrix(new Entity[, ] { { 1, 2 }, { 3, 4 } }); Assert.Equal(a, a.T.T); }
public void Identity2x3() { Assert.Equal( MathS.Matrix(new Entity[, ] { { 1, 0, 0 }, { 0, 1, 0 }, }), MathS.IdentityMatrix(2, 3)); }
[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); }
[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); }
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); }
[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); }
[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); }
[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); }
[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); }
[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); }
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()); }
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); }
[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); }
[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); }
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]); }
[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 } }) );