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.
| # | Name | Description |
|---|---|---|
| 1 | Fun | Integrating function. |
| 2 | Constants | Additional constants defining Fun function, usually nil/null. |
| 3 | ObjConst | Additional objects defining Fun function, usually nil/null. |
| 4 | lb | Defines lower bound. |
| 5 | ub | Defines pper bound. |
| 6 | N | Number of random points in [lb,ub] interval (see comments above). |
| 7 | FloatPrecision | Defines 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