Java 如何使用apachelib获取派生

Java 如何使用apachelib获取派生,java,apache,apache-commons,derivative,differentiation,Java,Apache,Apache Commons,Derivative,Differentiation,我正在使用apache库来计算派生。我想做的是得到以下的导数 方程式 我遵循下面发布的代码,但对于下面所述的参数,我有点困惑。 请帮我找出如何得到上述方程的导数 代码: int params = 1; int order = 2; double xRealValue = 5; DerivativeStructure x = new DerivativeStructure(params, order, 0, xRealValue); DerivativeStructure y = x.

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

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

代码

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

你用的是哪一个库版本?什么是。加(7)?为什么7你有2和5的总和,所以我加了7,如果你想的话,你可以把它分开。加(5)。加(2)我复制了你的答案,但是x用红色高亮显示你能告诉我怎么定义吗x@user2121你的x定义是正确的,所以我没有添加它。我也更新了答案。你能简要解释一下x定义参数的含义吗??我的意思是“params,order,index和xRealValue”,因为我只是随机地放置这些值,而不知道它们的含义
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);