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

时间:2015-09-30 11:56:26

标签: java apache math apache-commons-math

我已查阅了用户指南,但仍然不完全了解。对不起,这可能是一个糟糕的帖子。

1 个答案:

答案 0 :(得分:1)

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));

}