Example 2: Integral
The integral is computed and compared to its expected value.
import com.imsl.math.*;
public class QuadratureEx2 {
public static void main(String args[]) {
Quadrature.Function fcn = new Quadrature.Function() {
public double f(double x) {
return Math.exp(-x);
}
};
Quadrature q = new Quadrature();
double result = q.eval(fcn, 0.0, Double.POSITIVE_INFINITY);
double expect = 1.;
System.out.println("result = "+result);
System.out.println("expect = "+expect);
}
}
Output
result = 0.999999999999999
expect = 1.0
Link to Java source.