如何使用apache lib获取导数

How to get derivatives using apache lib

我正在使用 apache 库来计算导数。我想做的是得到以下的导数 等式

2+(2*x^2)+(3*x)+5

我遵循了下面发布的代码,但我对下面所述的参数有点困惑。 请帮我找出如何得到上述方程的导数。

代码:

int params = 1;
int order = 2;
double xRealValue = 5;
DerivativeStructure x = new DerivativeStructure(params, order, 0,  
    xRealValue);
DerivativeStructure y = x.pow(2);                    //COMPILE ERROR
Log.i(TAG, "y = " + y.getValue());
Log.i(TAG, "y = " + y.getPartialDerivative(1));
Log.i(TAG, "y = " + y.getPartialDerivative(2));

commons-math3 版本 3.6 没有给出任何编译错误,您的代码有效。

import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;

你的等式可以写成下面的形式

int xValue = 5;

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

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

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

//y = 2x^2 + 3x + 7
DerivativeStructure y = new DerivativeStructure(2.0, x2, 3.0, x).add(7);