資源簡介
蒙特卡洛積分方法,包括隨機(jī)點法和均值法。C語言實現(xiàn),包括封裝成動態(tài)庫的工程!

代碼片段和文件信息
#include?“MonterCarloIntegral.h“
#include?
#include?
#include?
static?double?ffun(pfun?g?double?x?double?a?double?b?double?c?double?d)
{
return?(g(a?+?(b?-?a)*x)?-?c)?/?(d?-?c);
}
?MCI_EXTERN?double?MCI_API(MCI_RandomPoint)(pfun?g?double?a?double?b?double?gmin?double?gmax)
{
double?S0?=?(b?-?a)*(gmax?-?gmin);
double?J?=?0;
const?static?int?RandNum?=?1E6;
int?_count?=?0;
srand((unsigned)time(NULL));
for?(int?i?=?0;?i? {
double?x?=?(double)rand()?/?(RAND_MAX?+?1);
double?y?=?(double)rand()?/?(RAND_MAX?+?1);
double?f?=?ffun(g?x?a?b?gmin?gmax);
if?(y?<=?f)_count++;
}
J?=?_count*1.0?/?RandNum;
return?S0*J?+?gmin*(b?-?a);;
}
?MCI_EXTERN?double?MCI_API(MCI_RandomPoint_V2)(pfun?g?double?a?double?b)
{
double?gmin?=?100000;
double?gmax?=?-100000;
double?x?y;
const?static?int?RandNumX?=?1E6;
for?(int?i?=?0;?i? {
x?=?a?+?(b?-?a)?*i?/?RandNumX;
y?=?g(x);
if?(gmin>y)gmin?=?y;
if?(gmax? }
gmin?-=?0.1;
gmax?+=?0.1;
return?MCI_RandomPoint(g?a?b?gmin?gmax);
}
?MCI_EXTERN?double?MCI_API(MCI_Mean)(pfun?g?double?a?double?b?double?gmin?double?gmax)
{
double?S0?=?(b?-?a)*(gmax?-?gmin);
double?J?=?0;
const?static?int?RandNum?=?1E6;
double?y?=?0;
srand((unsigned)time(NULL));
for?(int?i?=?0;?i? {
double?x?=?(double)rand()?/?(RAND_MAX?+?1);
y?+=?ffun(g?x?a?b?gmin?gmax);
}
J?=?y?/?RandNum;
return?S0*J?+?gmin*(b?-?a);;
}
?MCI_EXTERN?double?MCI_API(MCI_Mean_V2)(pfun?g?double?a?double?b)
{
double?gmin?=?100000;
double?gmax?=?-100000;
double?x?y;
const?static?int?RandNumX?=?1E6;
for?(int?i?=?0;?i? {
x?=?a?+?(b?-?a)?*i?/?RandNumX;
y?=?g(x);
if?(gmin>y)gmin?=?y;
if?(gmax? }
gmin?-=?0.1;
gmax?+=?0.1;
return?MCI_Mean(g?a?b?gmin?gmax);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-11-04?10:54??MonterCarloIntegral\
?????目錄???????????0??2017-11-04?10:51??MonterCarloIntegral\Debug\
?????文件???????32256??2017-11-04?10:51??MonterCarloIntegral\Debug\MonterCarloIntegral.dll
?????文件????????1039??2017-11-04?10:51??MonterCarloIntegral\Debug\MonterCarloIntegral.exp
?????文件??????201524??2017-11-04?10:51??MonterCarloIntegral\Debug\MonterCarloIntegral.ilk
?????文件????????2574??2017-11-04?10:51??MonterCarloIntegral\Debug\MonterCarloIntegral.lib
?????文件??????363520??2017-11-04?10:51??MonterCarloIntegral\Debug\MonterCarloIntegral.pdb
?????目錄???????????0??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\
?????文件?????2359296??2017-11-04?10:52??MonterCarloIntegral\MonterCarloIntegral.sdf
?????文件????????1003??2017-11-04?09:58??MonterCarloIntegral\MonterCarloIntegral.sln
?????文件???????18944??2017-11-04?10:52??MonterCarloIntegral\MonterCarloIntegral.v12.suo
?????目錄???????????0??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\
?????目錄???????????0??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\
?????文件?????????912??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\cl.command.1.tlog
?????文件????????2210??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\CL.read.1.tlog
?????文件?????????560??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\CL.write.1.tlog
?????文件????????1370??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\li
?????文件????????3034??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\li
?????文件?????????508??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\li
?????文件?????????160??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\MonterCarloIntegral.lastbuildstate
?????文件?????????774??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCa.DEB9AF95.tlog\MonterCarloIntegral.write.1u.tlog
?????文件????????2522??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCarloIntegral.log
?????文件???????12955??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\MonterCarloIntegral.obj
?????文件???????52224??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\vc120.idb
?????文件???????86016??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Debug\vc120.pdb
?????文件????????1933??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\MonterCarloIntegral.cpp
?????文件????????1140??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\MonterCarloIntegral.h
?????文件????????4195??2017-11-04?10:04??MonterCarloIntegral\MonterCarloIntegral\MonterCarloIntegral.vcxproj
?????文件????????1092??2017-11-04?10:04??MonterCarloIntegral\MonterCarloIntegral\MonterCarloIntegral.vcxproj.filters
?????目錄???????????0??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Release\
?????目錄???????????0??2017-11-04?10:51??MonterCarloIntegral\MonterCarloIntegral\Release\MonterCa.DEB9AF95.tlog\
............此處省略80個文件信息
評論
共有 條評論