简体   繁体   English

Apache Commons Math:获取派生/集成函数

[英]Apache Commons Math: get derivate/integrate function

I'm working with PolynomialFunction. 我正在使用PolynomialFunction。 I derivate/integrate my function f in the next way: 我通过以下方式派生/集成我的函数f

// derivation ...
new PolynomialFunction(vector).value(x).getPartialDerivative(derivationOrder)
// integration ...
UnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(pointsNumber, relativeAccuracy, absoluteAccuracy, minIterations, maxIterations);
integrator.integrate(128, f, from, to);

But how to get derivation/integration result from function f without specifying real values? 但是,如何在不指定实际值的情况下从函数f获取推导/积分结果呢?

Ie derivate (8 + 3x + x^2) => 3 + 2x 即导数(8 + 3x + x ^ 2)=> 3 + 2x

I do not believe the Apache Math Commons Library supports symbolic derivation/integration. 我不认为Apache Math Commons库支持符号派生/集成。 However, if you are using polynomials as your question implies, this is computationally easy enough. 但是,如果您所使用的问题是多项式,那么在计算上就很容易了。 If you represent a polynomial as an array of coefficients like Apache does for their PolynomialFunction, this makes it pretty easy. 如果将多项式表示为系数数组,就像Apache为其PolynomialFunction所做的那样,这将非常容易。

Derivative: 衍生物:

  1. Multiply each coefficient by the degree of its corresponding monomial (which happens to be the index of the coefficient). 将每个系数乘以其相应的单项式的次数(恰好是系数的索引)。
  2. Remove the 0 at the beginning of the array. 删除数组开头的0。

Integration: 积分:

  1. Divide each coefficient by the degree of its corresponding monomial + 1 (which is index+1). 将每个系数除以其对应的单项式的次数+1(即索引+1)。
  2. Add an undetermined constant to the beginning of the array (unless you are integrating from 0 to your variable, and then you can make it 0). 将不确定的常数添加到数组的开头(除非您将变量从0积分到变量,然后可以将其设为0)。

Doing this for an arbitrary function becomes a lot harder, or sometimes even impossible. 为任意功能执行此操作变得非常困难,有时甚至变得不可能。 There are programs out there that are pretty good at this, such as SageMath. 有一些非常擅长此功能的程序,例如SageMath。 I would consult a calculus text for more information. 我将咨询微积分文本以获取更多信息。 I hope that helps! 希望对您有所帮助!

For polynomial functions, you can get derivatives directly (as polynomials) using the polynomialDerivative method of the PolynomialFunction class. 对于多项式函数,可以使用PolynomialFunction类的polynomialDerivative方法直接获得导数(作为多项式)。 There is also a more general setup for differentiation described in the analysis section of the Commons Math User Guide. 在Commons Math用户指南的分析部分中介绍了用于区分的更通用的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM