⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 estimateareamc.m

📁 This set of files show some of the principles of Monte Carlo simulations, applied in the financila i
💻 M
字号:
function [Area] = EstimateAreaMC(xpoly,ypoly,maxsize,NbPoints,Method,VerboseOutput)

switch Method
    case 'Halton'
        P = haltonset(2);
        RandomPoints = maxsize .* net(P,NbPoints);
        k = 0;
    case 'Sobol'
        P = sobolset(2);
        RandomPoints = maxsize .* net(P,NbPoints);
    case 'Standard'
        RandomPoints = maxsize .* rand(NbPoints,2);
    otherwise
        error('Invalid Method');
end


IN = inpolygon(RandomPoints(:,1),RandomPoints(:,2),xpoly,ypoly);
Area = maxsize .* maxsize * sum(sum(IN)) ./ NbPoints;





hold on;

if (VerboseOutput)
    h = gcf;
    plot(RandomPoints(IN(:,end),end-1),RandomPoints(IN(:,end),end),'g.','LineWidth',1.5);
    plot(RandomPoints(~IN(:,end),end-1),RandomPoints(~IN(:,end),end),'rx','LineWidth',1.5);
    set(h,'WindowStyle','Docked');
    disp(['Area of the Polygon -> ' num2str(polyarea(xpoly,ypoly))]);
    disp(['Estimated Area of the Polygon  -> ' num2str( Area)]);
end





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -