How to use monte carlo method in matlab?

4 ビュー (過去 30 日間)
UCI
UCI 2013 年 2 月 3 日
編集済み: Saidou Nourou SOW 2020 年 3 月 17 日
I need to verify that pi = integral from 0 to 2 of(sqrt(4-x^2))dx using the monte carlo method and 10^7 random numbers. I am a little confused about how to implement this in matlab. Could someone help me out?
  2 件のコメント
Image Analyst
Image Analyst 2013 年 2 月 3 日
I don't see where your formula would take a random value (a number taken at random from some distribution).
Saidou Nourou SOW
Saidou Nourou SOW 2020 年 3 月 17 日
編集済み: Saidou Nourou SOW 2020 年 3 月 17 日
Hello. how to simulate, at each iteration, two independent processes (Xt) and (Yt) each following a random walk? do the following OLS regression: Yt = c + bXt + t.

サインインしてコメントする。

回答 (1 件)

Shashank Prasanna
Shashank Prasanna 2013 年 2 月 3 日
編集済み: Shashank Prasanna 2013 年 2 月 3 日
Here you go, hope you get full score on your assignment :)
f = @(x)sqrt(4-x.^2)
N = 1e7;
x = 2*rand(N,1);
intY = 2*sum(f(x))/N
Compare with:
intY = quad(f,0,2)

カテゴリ

Help Center および File ExchangeMonte-Carlo についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by