Example 1: Integral of exp(2x)
The integral is computed and compared to its expected value.
using System;
using Imsl.Math;
public class QuadratureEx1 : Quadrature.IFunction
{
public double F(double x)
{
return Math.Exp(2.0 * x);
}
public static void Main(String[] args)
{
Quadrature q = new Quadrature();
Quadrature.IFunction fcn = new QuadratureEx1();
double result = q.Eval(fcn, 1.0, 3.0);
double expect =
(System.Math.Exp(6) - System.Math.Exp(2)) / 2.0;
Console.Out.WriteLine("result = " + result);
Console.Out.WriteLine("expect = " + expect);
}
}
Output
result = 198.019868696902
expect = 198.019868696902
Link to C# source.