How to use monte carlo method in matlab?

조회 수: 2 (최근 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 CenterFile Exchange에서 Monte-Carlo에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by