VB_
VB_

Reputation: 45692

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?

I.e. derivate (8 + 3x + x^2) => 3 + 2x

Upvotes: 0

Views: 633

Answers (2)

Phil Steitz
Phil Steitz

Reputation: 644

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.

Upvotes: 1

user3846506
user3846506

Reputation: 196

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!

Upvotes: 1

Related Questions