1

我正在使用 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));
4

1 回答 1

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);
于 2016-03-04T10:50:55.113 回答