indiTraders - Forum for the Active Indian Trader  

Go Back   indiTraders - Forum for the Active Indian Trader > Tools > Software > Matlab

Reply
 
Bookmark and Share LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 19-08-2010, 06:44 AM
Oxymoron's Avatar
Oxymoron Oxymoron is offline
Super Moderator
 
Join Date: Mar 2009
Location: Chennai
Posts: 1,275
Thanks: 4,471
Thanked 4,825 Times in 1,156 Posts
Oxymoron has a reputation beyond repute
Oxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond reputeOxymoron has a reputation beyond repute
Default Matlab Code : Calculating Pi Using Monte Carlo

Hypothesis:
For a circle with radius (r) inscribed in a squared with side length 2r, the ratio of the area of circle/square = Pi/4

Assume there is a square that starts at the origin is of 2cm in side length. If we generate a random number for x co-ordinate and y co-ordinate, for this point to be inside the area circle, it must satisfy the equation:
x^2 + y^2 < r^2

=> No of randomly generated points within the circle/Total Generated Points must be equal to Pi/4

=> Approximation of Pi = 4*Points within circle/Total Points

Matlab Code:
Code:
%  Monte Carlo computation of pi.

n = input(' Enter n: ');
count = 0;

for i=1:n,
  x = 2*rand-1;  y = 2*rand-1;
  if x^2 + y^2 <= 1,  
  count = count + 1;  
  end;
end;

pi_approx = 4*(count/n);
Credits
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 5 Users Say Thank You to Oxymoron For This Useful Post:
  #2 (permalink)  
Old 30-08-2012, 09:22 PM
rg123 rg123 is offline
Newbie
 
Join Date: Aug 2012
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
rg123 is on a distinguished road
Default

You can also use parallel computing to speed it up. There is a link on this page for PI calculation using parallel computing and monte carlo:

Monte Carlo Simulation - MATLAB & Simulink
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to rg123 For This Useful Post:
Reply

indiTraders - Forum for the Active Indian Trader > Tools > Software > Matlab


Tags
computational finance, matlab, monte carlo simulation, random number generation

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 07:58 PM.


vBulletin Copyright by vBulletin

Content Relevant URLs by vBSEO 3.3.2