Class GaussianQuadratureIntegrator1D
- java.lang.Object
-
- com.opengamma.strata.math.impl.integration.Integrator1D<Double,Double>
-
- com.opengamma.strata.math.impl.integration.GaussianQuadratureIntegrator1D
-
- Direct Known Subclasses:
GaussHermiteQuadratureIntegrator1D
,GaussJacobiQuadratureIntegrator1D
,GaussLaguerreQuadratureIntegrator1D
,GaussLegendreQuadratureIntegrator1D
public abstract class GaussianQuadratureIntegrator1D extends Integrator1D<Double,Double>
Class that performs integration using Gaussian quadrature.If a function $f(x)$ can be written as $f(x) = W(x)g(x)$, where $g(x)$ is approximately polynomial, then for suitably chosen weights $w_i$ and points $x_i$, the integral can be approximated as: $$ \begin{align*} \int_{-1}^1 f(x)dx &=\int_{-1}^1 W(x)g(x)dx\\ &\approx \sum_{\i=1}^{n} w_i f(x_i) \end{align*} $$ The evaluation points, weights and valid limits of integration depend on the type of orthogonal polynomials that are used (see
OrthogonalPolynomialFunctionGenerator
andGaussLaguerreWeightAndAbscissaFunction
).
-
-
Constructor Summary
Constructors Constructor Description GaussianQuadratureIntegrator1D(int n, QuadratureWeightAndAbscissaFunction generator)
Creates an instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
abstract Function<Double,Double>
getIntegralFunction(Function<Double,Double> function, Double lower, Double upper)
Returns a function that is valid for both the type of quadrature and the limits of integration.abstract Double[]
getLimits()
Gets the limits.int
hashCode()
Double
integrate(Function<Double,Double> function, Double lower, Double upper)
1-D integration method.double
integrateFromPolyFunc(Function<Double,Double> polyFunction)
If a function $g(x)$ can be written as $W(x)f(x)$, where the weight function $W(x)$ corresponds to one of the Gaussian quadrature forms, then we may approximate the integral of $g(x)$ over a specific range as $\int^b_a g(x) dx =\int^b_a W(x)f(x) dx \approx \sum_{i=0}^{N-1} w_i f(x_i)$, were the abscissas $x_i$ and the weights $w_i$ have been precomputed.-
Methods inherited from class com.opengamma.strata.math.impl.integration.Integrator1D
integrate
-
-
-
-
Constructor Detail
-
GaussianQuadratureIntegrator1D
public GaussianQuadratureIntegrator1D(int n, QuadratureWeightAndAbscissaFunction generator)
Creates an instance.- Parameters:
n
- The number of sample points to be used in the integration, not negative or zerogenerator
- The generator of weights and abscissas
-
-
Method Detail
-
integrate
public Double integrate(Function<Double,Double> function, Double lower, Double upper)
1-D integration method.- Specified by:
integrate
in classIntegrator1D<Double,Double>
- Parameters:
function
- The function to integrate, not nulllower
- The lower bound, not nullupper
- The upper bound, not null- Returns:
- The result of the integration
-
integrateFromPolyFunc
public double integrateFromPolyFunc(Function<Double,Double> polyFunction)
If a function $g(x)$ can be written as $W(x)f(x)$, where the weight function $W(x)$ corresponds to one of the Gaussian quadrature forms, then we may approximate the integral of $g(x)$ over a specific range as $\int^b_a g(x) dx =\int^b_a W(x)f(x) dx \approx \sum_{i=0}^{N-1} w_i f(x_i)$, were the abscissas $x_i$ and the weights $w_i$ have been precomputed. This is accurate if $f(x)$ can be approximated by a polynomial.- Parameters:
polyFunction
- The function $f(x)$ rather than the full function $g(x) = W(x)f(x)$ This should be well approximated by a polynomial.- Returns:
- The integral
-
getLimits
public abstract Double[] getLimits()
Gets the limits.- Returns:
- The lower and upper limits for which the quadrature is valid
-
getIntegralFunction
public abstract Function<Double,Double> getIntegralFunction(Function<Double,Double> function, Double lower, Double upper)
Returns a function that is valid for both the type of quadrature and the limits of integration.- Parameters:
function
- The function to be integrated, not nulllower
- The lower integration limit, not nullupper
- The upper integration limit, not null- Returns:
- A function in the appropriate form for integration
-
-