Java - 您如何使用 apache commons 找到具有给定 x 值的函数(例如 f(x) = 2x^2+2x-1)的微分?

Java - How would you find the differential of a function (eg. f(x) = 2x^2+2x-1) with given values for x using apache commons?

我看了用户指南,还是不太明白。抱歉,这可能是一个错误 post。

public static void main(String[] args) {

    // change this for different results
    int xValue = 2;

    int howManyUnknowParamsHasFunction = 1;
    int howManyDeriviationWillYouTake = 1;
    int whatIsTheIndexOfThisParameterX = 0;

    DerivativeStructure x = new DerivativeStructure(howManyUnknowParamsHasFunction, howManyDeriviationWillYouTake, whatIsTheIndexOfThisParameterX, xValue);

    // x --> x^2.
    DerivativeStructure x2 = x.pow(2);

    //y = 2x^2 + 2x - 1
    DerivativeStructure y = new DerivativeStructure(2.0, x2, 2.0, x).subtract(1);

    System.out.println("y    = " + y.getValue());
    System.out.println("y'   = " + y.getPartialDerivative(1));

}