我正在使用Jscience线性代数模块来解决有理数的线性系统。这可以按预期工作并给出正确的结果:
public static void main(String[] args) {
DenseMatrix<Rational> m = DenseMatrix.valueOf(
DenseVector.valueOf(r(1, 1), r(-1, 1), r(0, 1), r(0, 1), r(1, 1), r(0, 1)),
DenseVector.valueOf(r(0, 1), r(0, 1), r(1, 1), r(-1, 1), r(0, 1), r(2, 1)),
DenseVector.valueOf(r(0, 1), r(0, 1), r(0, 1), r(0, 1), r(-1, 1), r(1, 1)),
DenseVector.valueOf(r(1, 1), r(0, 1), r(0, 1), r(0, 1), r(0, 1), r(0, 1)),
DenseVector.valueOf(r(0, 1), r(0, 1), r(0, 1), r(1, 1), r(0, 1), r(0, 1)),
DenseVector.valueOf(r(0, 1), r(-1, 1), r(1, 1), r(0, 1), r(0, 1), r(0, 1)));
DenseVector<Rational> v = DenseVector.valueOf(r(0, 1), r(0, 1), r(0, 1), r(0, 1), r(1, 1), r(1, 2));
Vector<Rational> sol = m.solve(v);
System.out.println(sol);
}
private static Rational r(int n, int d) {
return Rational.valueOf(n, d);
}
{0/1, 1/6, 2/3, 1/1, 1/6, 1/6}
代码将在执行时打印。
我的意图是解决这个系统中的一个组件的许多不同值v
,所以我将代码转换为使用RationalFunction<Rational>
而不是Rational
. 在第一步中,我还没有引入 a Variable
,everyRationalFunction<Rational>
是一个常数。我的理解是,这应该给出与以前相同的结果:
public static void main(String[] args) {
DenseMatrix<RationalFunction<Rational>> m = DenseMatrix.valueOf(
DenseVector.valueOf(r(1, 1), r(-1, 1), r(0, 1), r(0, 1), r(1, 1), r(0, 1)),
DenseVector.valueOf(r(0, 1), r(0, 1), r(1, 1), r(-1, 1), r(0, 1), r(2, 1)),
DenseVector.valueOf(r(0, 1), r(0, 1), r(0, 1), r(0, 1), r(-1, 1), r(1, 1)),
DenseVector.valueOf(r(1, 1), r(0, 1), r(0, 1), r(0, 1), r(0, 1), r(0, 1)),
DenseVector.valueOf(r(0, 1), r(0, 1), r(0, 1), r(1, 1), r(0, 1), r(0, 1)),
DenseVector.valueOf(r(0, 1), r(-1, 1), r(1, 1), r(0, 1), r(0, 1), r(0, 1)));
DenseVector<RationalFunction<Rational>> v = DenseVector.valueOf(r(0, 1), r(0, 1), r(0, 1), r(0, 1), r(1, 1), r(1, 2));
Vector<RationalFunction<Rational>> sol = m.solve(v);
System.out.println(sol);
}
private static RationalFunction<Rational> r(int n, int d) {
return RationalFunction.valueOf(Polynomial.valueOf(Rational.valueOf(n, d), Term.ONE), Polynomial.valueOf(Rational.ONE, Term.ONE));
}
但这在执行时会打印以下内容,即0/0
对于每个组件:
{([0/1])/([0/1]), ([0/1])/([0/1]), ([0/1])/([0/1]), ([0/1])/([0/1]), ([0/1])/([0/1]), ([0/1])/([0/1])}
Matrix.solve()
真的支持使用吗RationalFunction
?当我使用一对一矩阵对其进行测试时,它确实有效。
我接下来应该去哪里解决这个问题?