package com.imsl.test.example.math; import com.imsl.math.*; /** *

* Quadrature Example 3: Approximates the integral of the entire real line.

* * The integral $$\int_{-\infty}^\infty \frac{x} {4e^x + 9e^{-x}} \, dx$$ is * computed and compared to its expected value. This integral is evaluated in * Gradshteyn and Ryzhik (equation 3.417.1). * * @see Code * @see Output */ public class QuadratureEx3 { public static void main(String args[]) { Quadrature.Function fcn = new Quadrature.Function() { public double f(double x) { return x / (4 * Math.exp(x) + 9 * Math.exp(-x)); } }; Quadrature q = new Quadrature(); double result = q.eval(fcn, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); double expect = Math.PI * Math.log(1.5) / 12.; System.out.println("result = " + result); System.out.println("expect = " + expect); } }