필터 지우기
필터 지우기

Find square root using Monte carlo?

조회 수: 23 (최근 30일)
RSR
RSR 2015년 5월 19일
댓글: Walter Roberson 2023년 4월 11일
derive numerical value of square root of 2 using MC
  댓글 수: 2
James Tursa
James Tursa 2015년 5월 19일
Were you given any more instructions in the assignment? What have you done so far?
John D'Errico
John D'Errico 2015년 5월 19일
편집: James Tursa 2015년 5월 19일
Easy peasy. For example, to find the square root of 2...
X = 2;
Xroot = 1;
while Xroot.^2 ~= X
Xroot = X*rand;
end
When it converges, you are done. Of course, that may take some serious time. Just thinking, but I'm wondering just how many completely unworkable (but in theory, valid) answers I can think of for this problem? I'll bet I can think of at least a few more.
If you want a better answer, you will need to make more effort than simply posting your assignment.

댓글을 달려면 로그인하십시오.

답변 (2개)

Brandon
Brandon 2015년 5월 19일
This sounds like a homework assignment, so nobody here is going to answer it directly for you.
This website might give you some inspiration though: http://mathfaculty.fullerton.edu/mathews/n2003/montecarlopimod.html
In this problem, pi is the unknown value. Let's say you knew pi, would you be able to find another parameter? The answer is yes. Now how do you make that parameter equal to sqrt(2)...?

Walter Roberson
Walter Roberson 2015년 5월 19일
Generate a random value between 0 and 2. Square it. If the square is <= 2 then add 1 to a counter. Repeat this fixed number of times. The ratio between the counter and the number of times you repeated this will approach sqrt(2)/2.
  댓글 수: 2
Atishay Jain
Atishay Jain 2018년 2월 21일
I can't figure out why it will approach sqrt(2)/2 ... It's not areas of square with side sqrt(2)/ area of square with side 2.
What is it?
Thank you!
Walter Roberson
Walter Roberson 2023년 4월 11일
N = 100000;
approximation = mean((rand(1,N)*2).^2 <= 2)
approximation = 0.7081
square_root_2 = approximation * 2
square_root_2 = 1.4162
square_root_2 * square_root_2
ans = 2.0055

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by