Example 2: Integral of exp(-x) from 0 to infinity

The integral \int_0^\infty e^{-x} \, dx is computed and compared to its expected value.
using System;
using Imsl.Math;

public class QuadratureEx2 : Quadrature.IFunction
{
    public double F(double x)
    {
        return Math.Exp(- x);
    }


    public static void  Main(String[] args)
    {        
        Quadrature q = new Quadrature();
        Quadrature.IFunction fcn = new QuadratureEx2();
        double result = q.Eval(fcn, 0.0, Double.PositiveInfinity);
        
        double expect = 1.0;
        Console.Out.WriteLine("result = " + result);
        Console.Out.WriteLine("expect = " + expect);
    }
}

Output

result = 0.999999999999999
expect = 1

Link to C# source.