double MonteCarlo(TRealFunction Fun, double lb, double ub, const TMtxFloatPrecision FloatPrecision, TVec *Constants, const DewArray<tObject *> &ObjConst, int N = 65536);
Numerical integration by Monte Carlo method.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Fun | TRealFunction | Integrating function. |
| 2 | lb | double | Defines lower bound. |
| 3 | ub | double | Defines pper bound. |
| 4 | FloatPrecision | const TMtxFloatPrecision | Defines the computational precision to be used by the routine. |
| 5 | Constants | TVec * | Additional constants defining Fun function, usually nil/null. |
| 6 | ObjConst | const DewArray<tObject *> & | Additional objects defining Fun function, usually nil/null. |
| 7 | N = 65536 | int | Number of random points in [lb,ub] interval (see comments above). |
Returns: 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
#include "MtxIntDiff.h"
#include "MtxVec.h"
#include "Units.Math387.h"
#include "Units.MtxIntDiff.h"
using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units;
using namespace Dew::Math::Units::Math387;
static double IntFun(TVec* Parameters, TVec* c, const DewArray<tObject*>& o)
{
double x = (*Parameters)[0];
return Sin(x);
}
void Example()
{
TIntStopReason sr;
double area = MtxIntDiff::MonteCarlo(IntFun, 0.0, PI, TMtxFloatPrecision::mvDouble, null, null, 65536);
}
See Also: MtxIntDiff::QuadGauss
Declared in Dew::Math::Units::MtxIntDiff · Dew.Math/Units.MtxIntDiff.h · Cross-compiler