我正在尝试集成一个非常简单的功能。积分(x.dx)。当我从0到1包含限制时,我得到的答案为0或0.5,而不是得到1的答案。我是否有些误解了apache commons库中集成的实现?
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
***/
答案 0 :(得分:3)
我认为这是按预期运作的。您正在积分的函数是斜率1的直线。
在0到1之间,你得到的面积为0.5。在所有空间上方,上方和下方的积分抵消为0。