Class Quadrature


  • public class Quadrature
    extends java.lang.Object
    A collection of methods for integrating a 1D function within a range: I=int_a^b{f(x) dx}.

    Modified by: Joseph A. Huwaldt

    Version:
    February 14, 2025
    Author:
    Joseph A. Huwaldt Date: June 8, 2009
    • Constructor Summary

      Constructors 
      Constructor Description
      Quadrature()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double adaptLobatto​(Evaluatable1D func, double a, double b, double tol)
      Returns the integral of the supplied function from a to b using the adaptive Gauss-Lobatto method.
      Reference: Gander, W., Gautschi, W., "Adaptive Quadrature - Revisited", ETH Zürich, Aug.
      static double gaussLegendre_Wx1N10​(Evaluatable1D func, double a, double b)
      Returns the integral of the supplied function from a to b using Gauss-Legendre integration (W(x) = 1, N=10).
      static double gaussLegendre_Wx1N20​(Evaluatable1D func, double a, double b)
      Returns the integral of the supplied function from a to b using Gauss-Legendre integration (W(x) = 1, N=20).
      static double gaussLegendre_Wx1N40​(Evaluatable1D func, double a, double b)
      Returns the integral of the supplied function from a to b using Gauss-Legendre integration (W(x) = 1, N=40).
      static double simpsonsRule​(Evaluatable1D func, double a, double b, double tol)
      Returns the integral of the supplied function from a to b using Simpson's Rule.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • simpsonsRule

        public static double simpsonsRule​(Evaluatable1D func,
                                          double a,
                                          double b,
                                          double tol)
                                   throws IntegratorException,
                                          RootException
        Returns the integral of the supplied function from a to b using Simpson's Rule. Reference: Numerical Recipes in C, pg. 139.
        Parameters:
        func - The function being integrated (the "derivative" method is never called).
        a - The lower integration limit (must be < b).
        b - The upper integration limit (must be > a).
        tol - The desired relative error.
        Returns:
        The integral of the supplied function from a to b.
        Throws:
        IntegratorException - if to many iterations are attempted.
        RootException - thrown by the function itself.
      • gaussLegendre_Wx1N10

        public static double gaussLegendre_Wx1N10​(Evaluatable1D func,
                                                  double a,
                                                  double b)
                                           throws RootException
        Returns the integral of the supplied function from a to b using Gauss-Legendre integration (W(x) = 1, N=10). Reference: Numerical Recipes in C, pg. 148.
        Parameters:
        func - The function being integrated (the "derivative" function is never called).
        a - The lower integration limit (must be < b).
        b - The upper integration limit (must be > a).
        Returns:
        The integral of the supplied function from a to b.
        Throws:
        RootException - may be thrown by the function itself.
      • gaussLegendre_Wx1N20

        public static double gaussLegendre_Wx1N20​(Evaluatable1D func,
                                                  double a,
                                                  double b)
                                           throws RootException
        Returns the integral of the supplied function from a to b using Gauss-Legendre integration (W(x) = 1, N=20). Reference: Numerical Recipes in C, pg. 148.
        Parameters:
        func - The function being integrated (the "derivative" function is never called).
        a - The lower integration limit (must be < b).
        b - The upper integration limit (must be > a).
        Returns:
        The integral of the supplied function from a to b.
        Throws:
        RootException - may be thrown by the function itself.
      • gaussLegendre_Wx1N40

        public static double gaussLegendre_Wx1N40​(Evaluatable1D func,
                                                  double a,
                                                  double b)
                                           throws RootException
        Returns the integral of the supplied function from a to b using Gauss-Legendre integration (W(x) = 1, N=40). Reference: Numerical Recipes in C, pg. 148.
        Parameters:
        func - The function being integrated (the "derivative" function is never called).
        a - The lower integration limit (must be < b).
        b - The upper integration limit (must be > a).
        Returns:
        The integral of the supplied function from a to b.
        Throws:
        RootException - may be thrown by the function itself.
      • adaptLobatto

        public static double adaptLobatto​(Evaluatable1D func,
                                          double a,
                                          double b,
                                          double tol)
                                   throws IntegratorException,
                                          RootException
        Returns the integral of the supplied function from a to b using the adaptive Gauss-Lobatto method.
        Reference: Gander, W., Gautschi, W., "Adaptive Quadrature - Revisited", ETH Zürich, Aug. 1998.
        Parameters:
        func - The function being integrated (the "derivative" function is never called).
        a - The lower integration limit (must be < b).
        b - The upper integration limit (must be > a).
        tol - The desired relative error.
        Returns:
        The integral of the supplied function from a to b.
        Throws:
        IntegratorException - if to many iterations are attempted.
        RootException - may be thrown by the function itself.