diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java index 6bf93f041f..94baf44229 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/LinearAlgebra.java @@ -1009,8 +1009,18 @@ public static IAST generateCharacteristicPolynomial(int dim, IAST matrix, IExpr // new GenPolynomialRing>(cf, vars); // GenMatrix> A; // pf.charPolynomial(A); - final IExpr[] valuesForIdentityMatrix = {F.C0, variable}; - return F.Det(F.Subtract(matrix, diagonalMatrix(valuesForIdentityMatrix, dim))); + + return F.Det(subtractDiagonalValue(dim, matrix, variable)); + } + + private static IASTAppendable subtractDiagonalValue(int dimension, IAST matrix, IExpr value) { + IASTAppendable subtractMatrix = F.ListAlloc(dimension); + for (int i = 1; i < dimension + 1; i++) { + IASTMutable row = ((IAST) matrix.get(i)).copy(); + row.set(i, row.get(i).subtract(value)); + subtractMatrix.append(row); + } + return subtractMatrix; } @Override diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java index 40353628de..3c6bd74c5a 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LinearAlgebraTestCase.java @@ -73,6 +73,19 @@ public void testAntisymmetricMatrixQ() { "True"); } + + @Test + public void testCharacteristicPolynomial() { + check("CharacteristicPolynomial({{a, b}, {c, d}}, x)", // + "-b*c+a*d-a*x-d*x+x^2"); + check("CharacteristicPolynomial({{1, 1, 1}, {1, 1/2, 1/3}, {1, 2, 3}},x)", // + "-1/3-7/3*x+9/2*x^2-x^3"); + check("CharacteristicPolynomial(N({{1, 1, 1}, {1, 1/2, 1/3}, {1, 2, 3}}),x)", // + "-0.333333-2.33333*x+4.5*x^2-x^3"); + check("CharacteristicPolynomial({{1, 2*I}, {3 + 4*I, 5}}, z)", // + "13-I*6-6*z+z^2"); + } + @Test public void testCholeskyDecomposition() { check("matG=CholeskyDecomposition({{11.0,3.0},{3.0, 5.0}})", // diff --git a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java index 2fb0190ce1..7f92e9e6f7 100644 --- a/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java +++ b/symja_android_library/matheclipse-core/src/test/java/org/matheclipse/core/system/LowercaseTestCase.java @@ -2787,18 +2787,6 @@ public void testCharacters() { "{{\"t\",\"h\",\"i\"},{\"h\",\"i\",\"s\"},{\"i\",\"s\",\" \"},{\"s\",\" \",\"i\"},{\" \",\"i\",\"s\"},{\"i\",\"s\",\" \"},{\"s\",\" \",\"a\"},{\" \",\"a\",\" \"},{\"a\",\" \",\"s\"},{\" \",\"s\",\"t\"},{\"s\",\"t\",\"r\"},{\"t\",\"r\",\"i\"},{\"r\",\"i\",\"n\"},{\"i\",\"n\",\"g\"}}"); } - @Test - public void testCharacteristicPolynomial() { - check("CharacteristicPolynomial({{a, b}, {c, d}}, x)", // - "-b*c+a*d-a*x-d*x+x^2"); - check("CharacteristicPolynomial({{1, 1, 1}, {1, 1/2, 1/3}, {1, 2, 3}},x)", // - "-1/3-7/3*x+9/2*x^2-x^3"); - check("CharacteristicPolynomial(N({{1, 1, 1}, {1, 1/2, 1/3}, {1, 2, 3}}),x)", // - "-0.333333-2.33333*x+4.5*x^2-x^3"); - check("CharacteristicPolynomial({{1, 2*I}, {3 + 4*I, 5}}, z)", // - "13-I*6-6*z+z^2"); - } - @Test public void testCheck() { check("Check(0^(-42), failure)", // @@ -26430,6 +26418,8 @@ public void testValueQ() { @Test public void testVariables() { + check("Variables(FactorInteger(1232))", // + "{}"); check("Variables({x+y,x,z})", // "{x,y,z}"); check("Variables(x + f(x)+Pi*E)", //