如何在apache commons math3库中计算函数的集成? [英] How to compute integration of a function in apache commons math3 library?
本文介绍了如何在apache commons math3库中计算函数的集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试集成一个非常简单的功能。积分(x.dx)。我没有得到1的答案,我得到的答案为0或0.5,当我包含从0到1的限制时。有什么我误解了apache commons库中集成的实现吗?
I am trying to integrate a very simple function. integral(x.dx). Instead of getting an answer of 1, I am getting an answer as 0, or 0.5 when I include limits from 0 to 1. Is there something I misunderstand about the implementation of the integration in 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
***/
推荐答案
我认为这是按预期运作的。您正在积分的函数是斜率1的直线。
I think this is functioning as expected. The function you are integrating is the straight line of slope 1.
在0和1之间,您获得的面积为0.5。在所有空间中,上方和下方的积分抵消为0。
Between 0 and 1 you get an area of 0.5. Over all of the space the integrals above and below cancel out to give 0.
这篇关于如何在apache commons math3库中计算函数的集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文