2

我想使用 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

4

1 回答 1

3

假设您已导入org.jscience.mathematics.function.Variable$Local

(let [v (Variable$Local. "x")]
  ...)

也就是说,在将 Java 代码移植到 Clojure 时,您可以忽略类型参数,例如<Complex>. 请注意,嵌套类 likeLocal与它们的封闭类分开,带有$.

于 2012-09-25T14:49:52.777 回答