How to calculate function integration in math3 apache commons library?

I am trying to integrate a very simple function. Integral (x.dx). Instead of answer 1, I get the answer as 0 or 0.5 when I turn on the restrictions from 0 to 1. Is there something that I misunderstand about the implementation of integration in the apache commons library?

import org.apache.commons.math3.analysis.integration.*; import org.apache.commons.math3.analysis.polynomials.*; public static void main(String args[]) { SimpsonIntegrator simpson = new SimpsonIntegrator(); TrapezoidIntegrator trapezoid = new TrapezoidIntegrator(); double[] vector = new double[2]; vector[0] = 0; vector[1] = 1; PolynomialFunction f = new PolynomialFunction(vector); UnivariateFunction uf = (UnivariateFunction)new PolynomialFunction(vector); System.out.println("To String " + uf.toString()); System.out.println("Degree: " + f.degree()); double i = simpson.integrate(10, uf, -Float.MAX_VALUE, Float.MAX_VALUE); double j = trapezoid.integrate(10, uf, 0, 1); System.out.println("Simpson integral : " + i); System.out.println("Trapezoid integral : " + j); } /*** OUTPUT To String x Degree: 1 Simpson integral : 0.0 Trapezoid integral : 0.5 ***/ 
+4
source share
1 answer

I think this works as expected. The function you integrate is a straight slope line 1.

Between 0 and 1 you get an area of ​​0.5. Throughout the space, the integrals above and below cancel to give 0.

enter image description here

+3
source

Source: https://habr.com/ru/post/1484197/


All Articles