MtxIntDiff.MonteCarlo Method

function MonteCarlo(Fun: TRealFunction; lb: Double; ub: Double; const FloatPrecision: TMtxFloatPrecision; const Constants: TVec; const ObjConst: TObjectArray; N: Integer): Double;

Numerical integration by Monte Carlo method.

#NameDescription
1FunIntegrating function.
2ConstantsAdditional constants defining Fun function, usually nil/null.
3ObjConstAdditional objects defining Fun function, usually nil/null.
4lbDefines lower bound.
5ubDefines pper bound.
6NNumber of random points in [lb,ub] interval (see comments above).
7FloatPrecisionDefines the computational precision to be used by the routine.

Returns: Double - the numerical approximate on integral of function Fun between limits lb and ub.

Remarks:

Performs a numerical integration of function of single variable by using Monte Carlo method.

Examples
// Integrating function
function IntFunc(const Pars: TVec; const Constants: TVec; Const ObjConst: Array of TObject): double;
var x: double;
begin
    x := Pars[0];
    IntFunc := Sin(x);
end;
// Integrate
procedure DoIntegrate;
var area: double;
begin
    area := MonteCarlo(IntFunc,0,PI,16,[],[],65536); // 2^16 random points in [0,PI] interval
end;
See Also: MtxIntDiff.QuadGauss