# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.integration.univariate.riemann.gaussian

• java.lang.Object
• All Implemented Interfaces:
Integrator
Direct Known Subclasses:

public class GaussianQuadrature
extends Object
implements Integrator
A quadrature rule is a method of numerical integration in which we approximate the integral of a function by a weighted sum of sample points. That is, $\int_{a}^b f(x)\,dx \approx \sum_{i=1}^n c_i f(x_i).$

By a suitable choice of the points $$x_i$$ and the weights $$c_i$$, an n-point weighted sum will yield an exact result for polynomials of degree (2n-1) or less, which is known as a Gaussian quadrature rule.

Gaussian quadrature will only produce accurate results if $$f(x)$$ is well approximated by a polynomial function within the range [-1,1]. However, if the integrated function can be written as $$f(x) = W(x) g(x)$$ where $$g(x)$$ is approximately polynomial and $$W(x)$$ is known, then there are alternative weights $$w_i'$$ such that $\int_{a}^b f(x)\,dx =\int_{a}^b W(x) g(x)\,dx \approx \sum_{i=1}^n w_i' g(x_i).$

Note that the precision for Gaussian quadrature rules cannot be specified, and hence calling Integrator.getPrecision() will throw an UnsupportedOperationException.

• ### Constructor Summary

Constructors
Constructor and Description
GaussianQuadrature(GaussianQuadratureRule rule)
• ### Method Summary

All Methods
Modifier and Type Method and Description
double getPrecision()
Get the convergence threshold.
double integrate(UnivariateRealFunction f, double a, double b)
Integrate function f from a to b, $\int_a^b\! f(x)\, dx$
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

public GaussianQuadrature(GaussianQuadratureRule rule)
Parameters:
rule - the Gaussian quadrature rule
• ### Method Detail

• #### integrate

public double integrate(UnivariateRealFunction f,
double a,
double b)
Description copied from interface: Integrator
Integrate function f from a to b, $\int_a^b\! f(x)\, dx$
Specified by:
integrate in interface Integrator
Parameters:
f - a univariate function
a - the lower limit
b - the upper limit
Returns:
$$\int_a^b\! f(x)\, dx$$
• #### getPrecision

public double getPrecision()
Description copied from interface: Integrator
Get the convergence threshold. The usage depends on the specific integrator. For example, for an IterativeIntegrator, the integral is considered converged if the relative error of two successive sums is less than the threshold.
Specified by:
getPrecision in interface Integrator
Returns:
the precision