我想使用clojure来探索这个例子 - http://jscience.org/api/org/jscience/mathematics/function/package-summary.html
// Defines two local variables (x, y).
Variable<Complex> varX = new Variable.Local<Complex>("x");
Variable<Complex> varY = new Variable.Local<Complex>("y");
// f(x) = ix² + 2x + 1
Polynomial<Complex> x = Polynomial.valueOf(Complex.ONE, varX);
Polynomial<Complex> fx = x.pow(2).times(Complex.I).plus(
x.times(Complex.valueOf(2, 0)).plus(Complex.ONE));
System.out.println(fx);
System.out.println(fx.pow(2));
System.out.println(fx.differentiate(varX));
System.out.println(fx.integrate(varY));
System.out.println(fx.compose(fx));
// Calculates expression.
varX.set(Complex.valueOf(2, 3));
System.out.println(fx.evaluate());
我如何构建varX
?
答案 0 :(得分:3)
假设您已导入org.jscience.mathematics.function.Variable$Local
:
(let [v (Variable$Local. "x")]
...)
也就是说,在将Java代码移植到Clojure时,您可以忽略类型参数,例如<Complex>
。请注意,Local
等嵌套类与其$
的封闭类分开。