我正在使用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));
答案 0 :(得分:1)
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);