简体   繁体   中英

Apache Commons Math: get derivate/integrate function

I'm working with PolynomialFunction. I derivate/integrate my function f in the next way:

// 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?

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

I do not believe the Apache Math Commons Library supports symbolic derivation/integration. 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.

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.

Integration:

  1. Divide each coefficient by the degree of its corresponding monomial + 1 (which is index+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).

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. 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. There is also a more general setup for differentiation described in the analysis section of the Commons Math User Guide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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