You are here: Symbol Reference > MtxIntDiff Namespace > Functions > MtxIntDiff.MonteCarlo Function
MtxVec VCL
ContentsIndex
PreviousUpNext
MtxIntDiff.MonteCarlo Function

Numerical integration by Monte Carlo method.

Pascal
function MonteCarlo(Fun: TRealFunction; lb: double; ub: double; const FloatPrecision: TMtxFloatPrecision; Const Constants: TVec; Const ObjConst: Array of TObject; N: Integer = 65536): double;
Parameters 
Description 
Fun 
Integrating function. 
lb 
Defines lower bound. 
ub 
Defines pper bound. 
FloatPrecision 
Defines the computational precision to be used by the routine. 
Constants 
Additional constants defining Fun function, usually nil/null. 
ObjConst 
Additional objects defining Fun function, usually nil/null. 
Number of random points in [lb,ub] interval (see comments above). 

the numerical approximate on integral of function Fun between limits lb and ub.

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

Evaluate fuction Sin(x) on interval [0,PI] by using Monte Carlo algorithm.

// 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;
#include "MtxExpr.hpp" #include "Math387.hpp" #include "MtxIntDiff.hpp" double __fastcall IntFun(TVec* const Parameters, TVec* const Constants, System::TObject* const * ObjConst, const int ObjConst_Size) { double x = (*Parameters)[0]; return Math.Sin(x); } void __fastcall Example(); { double area = MonteCarlo(IntFun,0.0,PI,NULL,NULL,65536); // 2^16 random points in [0,PI] interval }
Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!