About Matlab Code

조회 수: 6 (최근 30일)
Techit
Techit 2011년 7월 12일
I want to ask about matlab's code of this clip >>http://www.youtube.com/watch?v=EbC0eP0Dq9A<<
Step for Algorithm .. 1. fix number of point for random . 2. when it ploted, separate which point in a circle and another out of circle. 3. after point are random finish, calculate ratio in a picture. by Ratio = (Rectangle's areas * all of point in a circle) / number of point for random
Sorry, If I spell grammar wrong..
  댓글 수: 1
Techit
Techit 2011년 7월 12일
yeah, thx for all comments :)
but i need some guild line for a code
because i can't understand that youtube comments
thanks agian
and i'm sorry for my newbie in this matlab

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

채택된 답변

Paulo Silva
Paulo Silva 2011년 7월 12일
clf
r=1;
rectangle('Position',[-1,-1,2*r,2*r],'Curvature',[1,1])
axis([-1 1 -1 1])
hold on
n=1000;
x=-1+2*r*rand(n,1);
y=-1+2*r*rand(n,1);
plot(x,y,'r.');
in=sum((x.^2+y.^2)<r);
(2*r)^2*in/n %Thanks Sean, (2*r)^2 is the area of the circle
Increasing n gives better approximations for the value of pi.
  댓글 수: 9
Paulo Silva
Paulo Silva 2011년 7월 12일
text(-0.5,1.1,['aproximmated \pi value=' num2str((2*r)^2*in/n)])
Techit
Techit 2011년 7월 12일
Thank you very much for your help.
> ขอบคุณครับ < I'm from Thailand :)

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

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 7월 12일
I think the answer to your question is already answered in the video comments.
  댓글 수: 9
Walter Roberson
Walter Roberson 2011년 7월 12일
Shouldn't that be
help rdivide
rather than ldivide ?
Sean de Wolski
Sean de Wolski 2011년 7월 12일
hmmm lt or le? The video says lt, but points on the circumference are part of the circle...

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


Sean de Wolski
Sean de Wolski 2011년 7월 12일
Alright - darkness golf
f=@(n)etc
I can do it with 38 characters (lt); 39 (le).

카테고리

Help CenterFile Exchange에서 Get Started with MuPAD에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by