-2

モンテカルロを使用して R^5 ハイパーキューブを統合する MATLAB コードを作成する必要があります。ジェネリック関数があるときに機能する基本的なアルゴリズムがあります。しかし、統合する必要がある機能は次のとおりです。

∫dA

A は R^5 の要素です。

∫f(x)dA があれば、私のアルゴリズムはうまくいくと思います。

アルゴリズムは次のとおりです。

% Writen by Jerome W Lindsey III

clear;
n = 10000;

% Make a matrix of the same dimension
% as the problem.  Each row is a dimension

A = rand(5,n);

% Vector to contain the solution

B = zeros(1,n);


    for k = 1:n
        % insert the integrand here
        % I don't know how to enter a function {f(1,n), f(2,n), … f(5n)} that
        % will give me the proper solution
        % I threw in a function that will spit out 5!
        % because that is the correct solution.
        B(k) = 1 / (2 * 3 * 4 * 5);

    end

mean(B) 
4

3 に答える 3

2

いずれにせよ、私はここでの意図が何であるかを理解していると思いますが、それはやや不自然な練習のように見えます. ここで説明されているように、MC を介して円の面積を見つけようとする問題を考えてみましょう。ここでは、サンプルが単位正方形から抽出されており、関数は円の内側で値 1 を取り、外側で 0 を取ります。R^5 で立方体の体積を求めるには、立方体を含む別のものからサンプリングし、類似の手順を使用して目的の体積を計算します。願わくば、これが残りの実装を簡単にするための十分なヒントになることを願っています。

于 2011-09-26T00:08:32.020 に答える
1

あなたが「正しい」答えとして与える数字は、あなたがエクササイズをどのように述べているか(単位ハイパーキューブの体積は1)と一致しないので、私はここで少し推測しています。

結果が 1/120 であることを考えると、標準シンプレックスをハイパーキューブに統合することになっているのでしょうか?

あなたの機能は明らかです。f(x) = 1 if sum(x) < 1; それ以外の場合は 0

于 2011-09-28T12:13:13.273 に答える
0
%Question 2, problem set 1
% Writen by Jerome W Lindsey III

clear;
n = 10000;

% Make a matrix of the same dimension
% as the problem.  Each row is a dimension
A = rand(5,n);

% Vector to contain the solution
B = zeros(1,n);


    for k = 1:n
        % insert the integrand here
        % this bit of code works as the integrand
        if sum(A(:,k)) < 1
            B(k) = 1;
        end

    end
    clear k;

clear A;

    % Begin error estimation calculations
    std_mc = std(B);
    clear n;
    clear B;

    % using the error I calculate a new random
    % vector of corect length
    N_new = round(std_mc ^ 2 * 3.291 ^ 2 * 1000000);
    A_new = rand(5, N_new);
    B_new = zeros(1,N_new);
    clear std_mc;

        for k = 1:N_new
            if sum(A_new(:,k)) < 1
                B_new(k) = 1;
            end
        end
        clear k;

    clear A_new;

    % collect descriptive statisitics
    M_new = mean(B_new);
    std_new = std(B_new);
    MC_new_error_999 = std_new * 3.921 / sqrt(N_new);
    clear N_new; 
    clear B_new;
    clear std_new;

% Display Results
disp('Integral in question #2 is');
disp(M_new);
disp(' ');
disp('Monte Carlo Error');
disp(MC_new_error_999);
于 2011-09-29T19:28:36.227 に答える