File Exchange

image thumbnail

Montecarlo method of pi calculation

version 1.1 (1.5 KB) by

Montecarlo method of pi calculation. No loops!!!

4 Downloads

Updated

View License

A circle of radius 0.5 is inscribed inside a square with side length 1.
Script picks N points at random inside the square. It then checks to see if the point is inside the circle and then generates a figure in which the points ''in'' and ''out'' are plotted in different colors. Say we have M points inside the circle. Pi is then approximated as follows:
% Pi = 4*M/N.
No loops!!!

Comments and Ratings (3)

Richard

Anon

Anon (view profile)

Please provide a proper title for your function. "Dr., professor" is a joke!

Sean de

Sean de (view profile)

-Malware script.
-Does do exactly what it says it does though and has a decent description.
-For educational purposes the direct calculation of the distance from the point to the center of the circle is better than using inpolygon (and probably more accurate).
-The 'MY' in the title makes it unnecessarily long.

Updates

1.1

I have changed the title

MATLAB Release
MATLAB 7.11 (R2010b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video