0

我正在尝试制作一个项目,其中涉及从原始数据及其导数计算插值。我有两个看起来像这样的数组:

A = { 1, 2, 3, 4, ... , n }
B = { 0.23, 0.43, 0.24, 0.19, ... , n }

我想要一个函数来描述以下数组,所以我使用 apache-common-math 库来插入将描述函数的多项式,其中:F(A[i]) = B[i]。之后,我希望计算这个函数的导数,以便能够找到极值(最大值/最小值)。

出于某种原因,我在衍生部分遇到了麻烦。

目前使用:

        DividedDifferenceInterpolator devider = new DividedDifferenceInterpolator();
        PolynomialFunctionNewtonForm polynom = devider.interpolate(xArray,  
        yArray);

现在我有了多项式,它是代表我以前的数组的函数。我应该如何计算它的导数..?

谢谢。

4

2 回答 2

1

您可以通过从牛顿形式多项式中提取系数,从中创建一个PolynomialFunction然后使用该函数的derivative方法来获得导数。这是一个例子:

double[] x = {0, 1, 2, 3, 4, 5};
double[] y = new double[6];
for (int i = 0; i < 6; i++) {
    y[i] = 1 + 2 * x[i] + 3 * x[i] * x[i];
}
DividedDifferenceInterpolator divider = new DividedDifferenceInterpolator();
PolynomialFunctionNewtonForm polynom = divider.interpolate(x, y);
double[] coefficients = polynom.getCoefficients();
System.out.println(Arrays.toString(coefficients));
PolynomialFunction derivative =
 (PolynomialFunction) new PolynomialFunction(coefficients).derivative();
System.out.println(Arrays.toString(derivative.getCoefficients()));

上面的代码从多项式 y = 1 + 2x + 3x^2 生成点。输出应该是

[1.0, 2.0, 3.0, 0.0, 0.0, 0.0]
[2.0, 6.0]
于 2015-04-21T23:59:11.960 回答
0

通过使用拉格朗日多项式而不是使用库,您可以很容易地找到多项式的导数。

您可以编写一个简单的函数(UnivariateFunction从 apache Commons 实现)。请参阅此页面上@Krokop 的方程式。

然后,您可以使用此处给出的 commons math 中的求根库,查看页面上给出的“典型用法”。

我不确定是否有更简单的方法。

于 2015-03-08T11:22:19.573 回答