Click or drag to resize
Accord.NET (logo)

RombergMethod Class

Romberg's method for numerical integration.
Inheritance Hierarchy
SystemObject
  Accord.Math.IntegrationRombergMethod

Namespace:  Accord.Math.Integration
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public class RombergMethod : IUnivariateIntegration, 
	INumericalIntegration, ICloneable
Request Example View Source

The RombergMethod type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyArea
Gets the numerically computed result of the definite integral for the specified function.
Public propertyFunction
Gets or sets the unidimensional function whose integral should be computed.
Public propertyRange
Gets or sets the input range under which the integral must be computed.
Public propertySteps
Gets or sets the number of steps used by Romberg's method. Default is 6.
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
Public methodCompute
Computes the area of the function under the selected Range. The computed value will be available at this object's Area.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberIntegrate(FuncDouble, Double, Double, Double)
Computes the area under the integral for the given function, in the given integration interval, using Romberg's method.
Public methodStatic memberIntegrate(FuncDouble, Double, Double, Double, Int32)
Computes the area under the integral for the given function, in the given integration interval, using Romberg's method.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

In numerical analysis, Romberg's method (Romberg 1955) is used to estimate the definite integral ∫_a^b(x) dx by applying Richardson extrapolation repeatedly on the trapezium rule or the rectangle rule (midpoint rule). The estimates generate a triangular array. Romberg's method is a Newton–Cotes formula – it evaluates the integrand at equally spaced points. The integrand must have continuous derivatives, though fairly good results may be obtained if only a few derivatives exist. If it is possible to evaluate the integrand at unequally spaced points, then other methods such as Gaussian quadrature and Clenshaw–Curtis quadrature are generally more accurate.

References:

Examples

Let's say we would like to compute the definite integral of the function f(x) = cos(x) in the interval -1 to +1 using a variety of integration methods, including the TrapezoidalRule, RombergMethod and NonAdaptiveGaussKronrod. Those methods can compute definite integrals where the integration interval is finite:

// Declare the function we want to integrate
Func<double, double> f = (x) => Math.Cos(x);

// We would like to know its integral from -1 to +1
double a = -1, b = +1;

// Integrate!
double trapez  = TrapezoidalRule.Integrate(f, a, b, steps: 1000); // 1.6829414
double romberg = RombergMethod.Integrate(f, a, b);                // 1.6829419
double nagk    = NonAdaptiveGaussKronrod.Integrate(f, a, b);      // 1.6829419

Moreover, it is also possible to calculate the value of improper integrals (it is, integrals with infinite bounds) using InfiniteAdaptiveGaussKronrod, as shown below. Let's say we would like to compute the area under the Gaussian curve from -infinite to +infinite. While this function has infinite bounds, this function is known to integrate to 1.

// Declare the Normal distribution's density function (which is the Gaussian's bell curve)
Func<double, double> g = (x) => (1 / Math.Sqrt(2 * Math.PI)) * Math.Exp(-(x * x) / 2);

// Integrate!
double iagk = InfiniteAdaptiveGaussKronrod.Integrate(g,
    Double.NegativeInfinity, Double.PositiveInfinity);   // Result should be 0.99999...
See Also