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