Example: HyperRectangle Quadrature
This example evaluates the following multidimensional integral, with n
=10.
import com.imsl.math.*;
public class HyperRectangleQuadratureEx1 {
public static void main(String args[]) {
HyperRectangleQuadrature.Function fcn =
new HyperRectangleQuadrature.Function() {
public double f(double x[]) {
int sign = 1;
double sum = 0.0;
for (int i = 0; i < x.length; i++) {
double prod = 1.0;
for (int j = 0; j <= i; j++) {
prod *= x[j];
}
sum += sign * prod;
sign = -sign;
}
return sum;
}
};
HyperRectangleQuadrature q = new HyperRectangleQuadrature(10);
double result = q.eval(fcn);
System.out.println("result = "+result);
}
}
Output
result = 0.3331253832089543
Link to Java source.