Example: HyperRectangle Quadrature
This example evaluates the following multidimensional integral, with n
=10.
using System;
using Imsl.Math;
public class HyperRectangleQuadratureEx1 :
HyperRectangleQuadrature.IFunction
{
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;
}
public static void Main(String[] args)
{
HyperRectangleQuadrature q = new HyperRectangleQuadrature(10);
double result = q.Eval(new HyperRectangleQuadratureEx1());
Console.Out.WriteLine("result = " + result);
}
}
Output
result = 0.333125383208954
Link to C# source.